package io.github.biezhi.elves.spider;

import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.SocketTimeoutException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import io.github.biezhi.elves.Elves;
import io.github.biezhi.elves.common.Constants;
import io.github.biezhi.elves.common.CookieConstants;
import io.github.biezhi.elves.common.MapConstants;
import io.github.biezhi.elves.config.Config;
import io.github.biezhi.elves.model.BulletinCourt;
import io.github.biezhi.elves.model.EbaseInfo;
import io.github.biezhi.elves.model.EnterpriseProfileInfo;
import io.github.biezhi.elves.model.ExecutorInfo;
import io.github.biezhi.elves.model.FamilyInvestmentInfo;
import io.github.biezhi.elves.model.LegalInfo;
import io.github.biezhi.elves.model.MainPersonnel;
import io.github.biezhi.elves.model.NoticeCourt;
import io.github.biezhi.elves.model.RefereeDoc;
import io.github.biezhi.elves.model.Shareholder;
import io.github.biezhi.elves.model.StockStructureInfo;
import io.github.biezhi.elves.ok.http.FastHttpClient;
import io.github.biezhi.elves.pipeline.Pipeline;
import io.github.biezhi.elves.property.CityProperty;
import io.github.biezhi.elves.request.Request;
import io.github.biezhi.elves.response.Response;
import io.github.biezhi.elves.response.Result;
import io.github.biezhi.elves.selenium.QccSelenium;
import io.github.biezhi.elves.service.FamilyInvestmentService;
import io.github.biezhi.elves.service.RelationProfileService;
import io.github.biezhi.elves.service.ShareholderService;
import io.github.biezhi.elves.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * 爬取企查查网站信息数据入库类(代码写得不够好，日后优化)
 * 
 * 包括企业的法人代表、股东、主要人员、股东结构
 *
 */
@Slf4j
@Configuration
public class ShareholderSpider extends Spider {
	@Autowired
	private CityProperty cityProperty;
	private static CityProperty staticCityProperty;
	
	@Autowired
	private ShareholderService staticShareholderService;
	private static ShareholderService shareholderService;
	
	@Autowired
	private FamilyInvestmentService staticFamilyInvestmentService;
	private static FamilyInvestmentService familyInvestmentService;
	
	@Autowired
	private RelationProfileService staticRelationProfileService;
	private static RelationProfileService relationProfileService;
	
	@Bean
	public CityProperty getCityPropertyBean(){
		if(cityProperty!=null){
			staticCityProperty = cityProperty;
			return staticCityProperty;
		}
		return null;
	}
	
	@Bean
	public ShareholderService getShareholderServiceBean(){
		if(staticShareholderService!=null){
			shareholderService = staticShareholderService;
			return shareholderService;
		}
		return null;
	}
	
	@Bean
	public FamilyInvestmentService getFamilyInvestmentServiceBean(){
		if(staticFamilyInvestmentService!=null){
			familyInvestmentService = staticFamilyInvestmentService;
			return familyInvestmentService;
		}
		return null;
	}
	
	@Bean
	public RelationProfileService getRelationProfileServiceBean(){
		if(staticRelationProfileService!=null){
			relationProfileService = staticRelationProfileService;
			return relationProfileService;
		}
		return null;
	}
	
	final String splitString = ",";
	//处理量
	int handleCount = 0;
	//要爬取企业数据结果量
	int crawlTableDataCount = 0;
	//定义数据库企业名称没有匹配到企查查网站数据的量
	int countIsNull = 0;
	//定义某企业法律诉讼量
	int susontCount = 0;
	//定义某企业不存在法律诉讼量
	int susontCountIsNull = 0;
	
	static int pageNo = 1;
	static int pageSize = 20;
	static final int updatePageSize = Constants.UPDATE_PAGE_SIZE;
	
	//定义企查查列表查询可查最大分页数
	static final int maxSearchPageNo = 3;
	
	//最大爬取数据量
	static final int maxRunSize = 40;
	
	static String urlEntname = "&entname=";
	static String requestEntnameTrimVal = "";
	final String indexUrl = "http://www.qichacha.com";
	final String contentAsynUrl = "/company_getinfos?";
	final String contentCmsAsynUrl = "/cms_guquanmap";
	final String contentBusinessAsynUrl = "/cms_businessmap";
	static String unique = "";
	static String companyname = "";
	static String[] tabs = new String[]{"base","susong","run","touzi","report","assets","history"};
	static String[] targetEntnames = new String[]{"0093（营运牌号）","0099（营运牌号 ）","0132(营运牌号）","0333（营运牌号 ）",
			"0333（营运牌号 ）","0347  0343",":和平县物资总公司液化石油气站安坳章记代销点",";乐昌市有间音像店",
			"A--1钻具工具有限公司","A-1钻具和工具公司(鸿图有限公司分部)","?清新县浸潭镇大罗山一、二级水电站","?齘啤酒〔联营〕公司珠海特区分公司商场",
			"Casio Computer （Hong Kong）Ltd.深圳代表处","Cenix (HK) Limited 深圳代表处"};
	static String[] indexOfs = new String[]{",","-",".","/"};
	static String cookieVal = CookieConstants.QYY_CCA_COOKIE;
	final String qichachaSearchUrl = "http://www.qichacha.com/search?key=";
	List<EbaseInfo> crawlTableDataList = null;
	List<EbaseInfo> crawlTableDataIsNullList = null;
	List<EbaseInfo> crawlTableDataIsNotNullList = null;
	
	public ShareholderSpider(){}
	
	public ShareholderSpider(String name) throws Exception {
		super(name);
		
		//获取要爬取企业列表数量
		pageSize = shareholderService.getPaiquNumber();
		System.out.println(this.getClass().getName() + "[{}]==>当前页数:" + pageNo + "，每页显示记录数:" + pageSize);
		//分页查询爬取列表数据
		String urls = queryCrawlTableDataList(pageNo, pageSize);
		if(!StringUtils.isNullOrEmpty(urls)){
			this.startUrls(urls.split(splitString));
		}
	}

	/**
	 * 开始根据执行企业名称批量更新爬取列表数据表地市id和地市名称
	 * @throws Exception 
	 */
	public void startBatchUpdateCrawlTableDataForCityIdAndCityName() throws Exception{
		int pageNo1 = 0;
		while(true){
			pageNo1++;
			int countCity = shareholderService.countCrawlTableDataByCityId("4401");
			//根据企业名称批量更新爬取列表数据表地市id和地市名称
			batchUpdateCrawlTableDataForCityIdAndCityName(pageNo1,countCity);
		}
	}
	
	/**
	 * 根据企业名称批量更新爬取列表数据表地市id和地市名称
	 * @param countCity
	 * @throws Exception 
	 */
	static int cityTotal = 1286194;
	private void batchUpdateCrawlTableDataForCityIdAndCityName(int pageNo1,int countCity) throws Exception{
		List<EbaseInfo> list = new ArrayList<EbaseInfo>();
		
		System.out.println(this.getClass() + ".batchUpdateCrawlTableDataForCityIdAndCityName[{}]==>当前页数:" + pageNo1 + "，每页显示记录数:" + updatePageSize);
		//获取要工商列表数据(分页)
		List<EbaseInfo> ebaseInfoPageList = shareholderService.queryEbaseInfoForCityIdPage(pageNo1,updatePageSize);
		if(ebaseInfoPageList!=null && ebaseInfoPageList.size()>0){
			if(cityTotal>countCity){
				for(int i = 0; i<ebaseInfoPageList.size(); i++){
					EbaseInfo ebaseInfo = ebaseInfoPageList.get(i);
					String cityId = ebaseInfo.getRegorg().substring(0,4);
					String cityName = StringUtils.getValueForKey(cityId, MapConstants.cityMap);
					ebaseInfo.setRegorg(cityId);
					ebaseInfo.setCityName(cityName);
					list.add(ebaseInfo);
				}
				//根据企业名称批量更新爬取列表数据表地市id和地市名称
				shareholderService.batchUpdateCrawlTableDataForCityIdAndCityName(list);
				countCity = shareholderService.countCrawlTableDataByCityId("4401");
				System.err.println("共要更新数据量为{{}}==>" + ebaseInfoPageList.size());
				System.err.println("已更新爬取数据列表中city_id和city_name字段值数据量{{}}==>" + countCity);
			}else{
				System.err.println("已更新完爬取数据列表中city_id和city_name字段值数据量，程序自动停止!!!");
				System.exit(0);
			}
		}
	}
	
	/**
	 * 开始根据地市ID补充企业图谱数据
	 * @throws Exception 
	 */
	public void startSupplementEnterpriseProfileData() throws Exception{
		int pageNum = 0;
		while(true){
			pageNum++;
			//补充企业图谱数据
			supplementEnterpriseProfileData(pageNum,"4401");
		}
	}
	
	/**
	 * 补充企业图谱数据
	 * @param pageNum
	 * @param cityId
	 * @param requestUrl
	 */
	@SuppressWarnings("deprecation")
	public void supplementEnterpriseProfileData(int pageNum, String cityId) {
		//企业图谱数据获取
		try{
			System.out.println(this.getClass() + ".supplementEnterpriseProfileData[{}]==>当前页数:" + pageNum + "，每页显示记录数:" + updatePageSize);
			//获取法人代表数据(分页)
			List<LegalInfo> legalInfoPageList = shareholderService.getLegalInfoPageByCityId(pageNum,updatePageSize,cityId);
			if(legalInfoPageList!=null && legalInfoPageList.size() > 0) {
				int index = 0;
				for(LegalInfo legalInfo : legalInfoPageList) {
					
					index++;
					
					String entname = legalInfo.getEntname();
					System.out.println("======开始新增第" + index + "条，" + entname + "企业图谱数据=====");
					System.out.println();
					
					String requestEntnameVal = URLEncoder.encode(entname);
					String uniqueId = legalInfo.getUniqueId();
					String cmsAsynUrl = indexUrl + contentBusinessAsynUrl + "?keyNo=" + uniqueId;
					//返回响应url内容
					String jsonStr = getHttpForJsonData(cmsAsynUrl,requestEntnameVal);
					if(!StringUtils.isNullOrEmpty(jsonStr)){
						try{
							JSONObject json = JSONObject.parseObject(jsonStr);
							String status = json.getString("Status");
							if(json.containsKey("Status") && "200".equals(status)){
								//解析json数据并保存企业图谱数据入库
								saveEnterpriseProfileData(cmsAsynUrl,jsonStr,uniqueId,entname,requestEntnameVal);
							}else{
								System.err.println("企业图谱Status状态值非200，状态值为{{}}==>" + status + "，企业名称{{}}==>" + entname + "，json串{{}}==>" + jsonStr);
							}
						}catch(Exception e){
							System.out.println("处理企业图谱数据异常{{}}==>" + StringUtils.getErrorInfoFromException(e));
						}
					}
				}
				
				//查询企业图谱表总数
				int countEnterpriseProfile = shareholderService.countEnterpriseProfileInfo("4401");
				System.err.println("共要补充数据量为{{}}==>" + legalInfoPageList.size());
				System.err.println("已补充企业图谱数据量{{}}==>" + countEnterpriseProfile);
			} else {
				System.out.println();
				System.out.println("======已完成企业图谱数据补充，系统自动停止======");
				System.exit(0);
			}
		}catch(Exception e){
			System.out.println("企业图谱解析json数据异常{{}}==>" + e.getMessage());
		}
	}
	
	/**
	 * 开始根据地市ID补充投资族谱数据
	 * @throws Exception 
	 */
	public void startFamilyInvestmentInfoData() throws Exception{
		int pageNum = 0;
		while(true){
			pageNum++;
			//补充投资族谱数据
			familyInvestmentService.supplementFamilyInvestmentInfoData(pageNum,"4401");
		}
	}
	
	/**
	 * 开始关联图谱数据测试
	 * @throws Exception 
	 */
	public void startRelationProfileInfoData() throws Exception{
		String entname = "广州蓝实通电子科技有限公司";
		String requestEntnameVal = URLEncoder.encode(entname);
		String cmsAsynUrl = StringUtils.getValueForKey("company_muhouAction", MapConstants.QCC_REQUEST_URL_MAP) + "277b9cc7bc66245fbc26f08bf7362df3";
		//返回响应url内容
		String jsonStr = StringUtils.getQccGetHttpForJsonData(cmsAsynUrl,requestEntnameVal);
		
		//关联图谱数据
		relationProfileService.saveRelationProfileData(cmsAsynUrl, jsonStr, unique, entname, requestEntnameVal);
	}
	
	/**
	 * 开始执行爬虫企查查操作
	 * @throws Exception 
	 */
	public void startShareholder() throws Exception{
		ShareholderSpider shareholderSpider = new ShareholderSpider("广东工商企业");
		Elves.me(shareholderSpider, Config.me()).start();
	}
	
	@Override
	public void onStart(Config config) {
		this.addPipeline((Pipeline<List<String>>) (item, request) -> log.info("保存到文件: {}", item));
	}
	
	/**
	 * 爬取企业数据
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public Result parse(Response response) {
		//根据企业名称精确匹配数据
		return parseSearchByEntname(response);
	}
	
	/**
	 * 根据企业名称精确匹配数据
	 * @throws Exception 
	 */
	@SuppressWarnings({ "deprecation", "rawtypes" })
	public Result<List<String>> parseSearchByEntname(Response response) {
		String requestUrl = response.getRequest().getUrl();
		System.out.println(this.getClass() + ".parseSearchByEntname{{}}==>" + requestUrl);
		
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println("urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("key")){
			requestEntnameTrimVal = StringUtils.getValueForKey("key", urlParamMap);
			requestEntnameTrimVal = URLDecoder.decode(requestEntnameTrimVal);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		
		int index = 0;
		int pageIndex = 0;
		boolean needNextPage = true;
		//获取企业
		Elements elements = response.body().css(".row .col-md-9 #ajaxlist section.panel > table > tbody > tr");
		if(elements!=null && elements.size()>0){
			if(crawlTableDataIsNullList!=null && crawlTableDataIsNullList.size()>0){
			}else{
				crawlTableDataIsNullList = new ArrayList<EbaseInfo>();
			}
			if(crawlTableDataIsNotNullList!=null && crawlTableDataIsNotNullList.size()>0){
			}else{
				crawlTableDataIsNotNullList = new ArrayList<EbaseInfo>();
			}
			for(Element element : elements){
				String entname = element.select("td").get(1).select("a.ma_h1").text();
				String requestReplaceEntnameTrimVal = requestEntnameTrimVal.replace("（", "(").replace("）", ")");
				requestReplaceEntnameTrimVal = requestReplaceEntnameTrimVal.replace(" ", "");
				
				for(String indexOfStr : indexOfs){
					if(requestReplaceEntnameTrimVal.indexOf(indexOfStr)==0){
						requestReplaceEntnameTrimVal = requestReplaceEntnameTrimVal.substring(requestReplaceEntnameTrimVal.indexOf(indexOfStr)+1);
						break;
					}
				}
				
				for(String targetEntname : targetEntnames){
					if(requestEntnameTrimVal.equals(targetEntname)){
						requestReplaceEntnameTrimVal = entname;
						break;
					}
				}
				if("**名潮网吧**".equals(requestReplaceEntnameTrimVal)){
					requestReplaceEntnameTrimVal = entname;
				}else{
					requestReplaceEntnameTrimVal = requestReplaceEntnameTrimVal.replace("*", "");
				}
				
				System.out.println(this.getClass() + ".parseContent变量entname{{}}==>" + entname);
				System.out.println(this.getClass() + ".parseContent变量requestEntnameTrimVal{{}}==>" + requestEntnameTrimVal);
				System.out.println(this.getClass() + ".parseContent变量requestReplaceEntnameTrimVal{{}}==>" + requestReplaceEntnameTrimVal);
				
				if((entname==null || "".equals(entname)) || (!requestEntnameTrimVal.equals(entname) && !requestReplaceEntnameTrimVal.equals(entname))){
//					pageIndex++;
					if(needNextPage && (elements!=null && pageIndex==elements.size())){
						// 获取下一页 URL
						Elements nextEl = response.body().css("#ajaxlist > div > .m-t-lg > ul.pagination > li > a");
						if(nextEl==null || nextEl.size()==0){
							nextEl = response.body().css("div > .m-t-lg > ul.pagination > li > a");
						}
						if (null != nextEl && nextEl.size() > 0) {
							try{
								String href = "";
								String hrefText = "";
								for(Element pageElement : nextEl){
									hrefText = pageElement.select("a").text();
									if(">".equals(hrefText)){
										href = pageElement.select("#ajaxpage").attr("href");
										break;
									}else{
										continue;
									}
								}
								if(">".equals(hrefText)){
									String nextPageNoStr = href.replace("javascript:getSearchPage(", "").replace(")", "");
									nextPageNoStr = nextPageNoStr.substring(0,nextPageNoStr.indexOf(","));
									int nextPageNo = Integer.parseInt(nextPageNoStr);
									String nextPageUrl = indexUrl + "/search_index?key=" + URLEncoder.encode(requestEntnameTrimVal) + urlEntname + requestEncodeEntnameVal + "&ajaxflag=1&p="+ nextPageNo + "&";
									//返回响应url内容
									String responseBody = getHttpReponseBody(nextPageUrl);
									//企查查列表查询每页内容
									parseSearchContentPage(nextPageUrl, responseBody);
								}else{
									//数据库企业名称与企查查网站查询结果没有匹配上,则插入数据库的企业名称与pripid(主体身份代码),只会在app_legal_info(法人代表信息表)有记录
									if(index==(elements.size()-1)){
										//保存法人代表数据(是没有匹配上企查查网站的企业，插入数据库，只有企业名称(entname)和主体身份代码(entname)有值)
										saveLegalInfo(requestEntnameVal);
										countIsNull++;
										EbaseInfo ebaseInfo = new EbaseInfo(requestEntnameVal);
										crawlTableDataIsNullList.add(ebaseInfo);
									}
								}
							}catch(Exception e){
								System.out.println("企查查列表查询下一页数据获取异常{{}}==>" + e.getMessage());
							}
						}
					}else{
						//数据库企业名称与企查查网站查询结果没有匹配上,则插入数据库的企业名称与pripid(主体身份代码),只会在app_legal_info(法人代表信息表)有记录
						if(index==(elements.size()-1)){
							//保存法人代表数据(是没有匹配上企查查网站的企业，插入数据库，只有企业名称(entname)和主体身份代码(entname)有值)
							saveLegalInfo(requestEntnameVal);
							countIsNull++;
							EbaseInfo ebaseInfo = new EbaseInfo(requestEntnameVal);
							crawlTableDataIsNullList.add(ebaseInfo);
						}
					}
					index++;
					continue;
				}else{
					needNextPage = false;
//					String legalName = element.select("p.m-t-xs > a.text-primary").text();
					String titleUrl = element.select("td").get(1).select("a").attr("href");
					String jyStatus = element.select("td").get(2).select("span.nstatus").text();
					System.out.println("entname==>" + entname);
					System.out.println("href==>" + titleUrl);
					System.out.println("jyStatus==>" + jyStatus);
					
					String clickTitleUrl = indexUrl + titleUrl;
					if(clickTitleUrl.indexOf("?")==-1){
						clickTitleUrl += "?companyname="+URLEncoder.encode(entname.trim()) + urlEntname + requestEncodeEntnameVal;
					}else{
						if(clickTitleUrl.indexOf("?")!=-1){
							clickTitleUrl += "&companyname="+URLEncoder.encode(entname.trim()) + urlEntname + requestEncodeEntnameVal;
						}
					}
//					clickTitleUrl = "http://www.qichacha.com/firm_4359198d09bf3237ae0465f6d40ef43a.html";
					Request clickTitleReq = this.makeRequest(clickTitleUrl, this::parseContentAsynGetUrl);
					result.addRequest(clickTitleReq);
					break;
				}
			}
		}
		//处理并验证数据结果
		handleDataResult();
		return result;
	}
	
	/**
	 * 获取企查查列表查询每页内容
	 * @param requestUrl
	 * @param responseBodyContent
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	private Result<List<String>> parseSearchContentPage(String requestUrl,String responseBodyContent){
		System.out.println(this.getClass() + ".parseSearchContentPage{{}}==>" + requestUrl);
//		System.out.println(this.getClass() + ".parseSearchContentPage{{}}==>" + responseBodyContent);
		
		int pageNo = 0;
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass().getName() + ",urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		
		if(urlParamMap!=null && urlParamMap.containsKey("key")){
			requestEntnameTrimVal = StringUtils.getValueForKey("key", urlParamMap);
			requestEntnameTrimVal = URLDecoder.decode(requestEntnameTrimVal);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("p")){
			pageNo = StringUtils.getIntValueForKey("p", urlParamMap);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		Document doc = Jsoup.parse(responseBodyContent);
		
		int index = 0;
		int pageIndex = 1;
		boolean needNextPage = true;
		Elements elements = doc.select(".row .col-md-9 #ajaxlist section.panel > table > tbody > tr");
		if(elements==null || elements.size()==0){
			elements = doc.select("#searchlist > table > tbody > tr");
		}
		if(elements!=null && elements.size()>0){
			if(crawlTableDataIsNullList!=null && crawlTableDataIsNullList.size()>0){
			}else{
				crawlTableDataIsNullList = new ArrayList<EbaseInfo>();
			}
			for(Element element : elements){
				String entname = element.select("td").get(1).select("a.ma_h1").text();
				String requestReplaceEntnameTrimVal = requestEntnameTrimVal.replace("（", "(").replace("）", ")");
				requestReplaceEntnameTrimVal = requestReplaceEntnameTrimVal.replace(" ", "");
				
				for(String indexOfStr : indexOfs){
					if(requestReplaceEntnameTrimVal.indexOf(indexOfStr)==0){
						requestReplaceEntnameTrimVal = requestReplaceEntnameTrimVal.substring(requestReplaceEntnameTrimVal.indexOf(indexOfStr)+1);
						break;
					}
				}
				
				for(String targetEntname : targetEntnames){
					if(requestEntnameTrimVal.equals(targetEntname)){
						requestReplaceEntnameTrimVal = entname;
						break;
					}
				}
				if("**名潮网吧**".equals(requestReplaceEntnameTrimVal)){
					requestReplaceEntnameTrimVal = entname;
				}else{
					requestReplaceEntnameTrimVal = requestReplaceEntnameTrimVal.replace("*", "");
				}
				
				System.out.println(this.getClass() + ".parseContent变量entname{{}}==>" + entname);
				System.out.println(this.getClass() + ".parseContent变量requestEntnameTrimVal{{}}==>" + requestEntnameTrimVal);
				System.out.println(this.getClass() + ".parseContent变量requestReplaceEntnameTrimVal{{}}==>" + requestReplaceEntnameTrimVal);
				
				if((entname==null || "".equals(entname)) || (!requestEntnameTrimVal.equals(entname) && !requestReplaceEntnameTrimVal.equals(entname))){
					pageIndex++;
					if(pageNo < maxSearchPageNo){
						if(needNextPage && (elements!=null && pageIndex==elements.size())){
							// 获取下一页 URL
							Elements nextEl = doc.select("#ajaxlist > div > .m-t-lg > ul.pagination > li > a");
							if(nextEl==null || nextEl.size()==0){
								nextEl = doc.select("div > .m-t-lg > ul.pagination > li > a");
							}
							if (null != nextEl && nextEl.size() > 0) {
								try{
									String href = "";
									String hrefText = "";
									for(Element pageElement : nextEl){
										hrefText = pageElement.select("a").text();
										if(">".equals(hrefText)){
											href = pageElement.select("#ajaxpage").attr("href");
											break;
										}else{
											continue;
										}
									}
									if(">".equals(hrefText)){
										String nextPageNoStr = href.replace("javascript:getSearchPage(", "").replace(")", "");
										nextPageNoStr = nextPageNoStr.substring(0,nextPageNoStr.indexOf(","));
										int nextPageNo = Integer.parseInt(nextPageNoStr);
										String nextPageUrl = indexUrl + "/search_index?key=" + URLEncoder.encode(requestEntnameTrimVal) + urlEntname + requestEncodeEntnameVal + "&ajaxflag=1&p="+ nextPageNo + "&";
										System.out.println("第" + pageNo + "页，searchPageNextPageUrl{{}}==>" + nextPageUrl);
										//返回响应url内容
										String responseBody = getHttpReponseBody(nextPageUrl);
										//企查查列表查询每页内容
										parseSearchContentPage(nextPageUrl, responseBody);
									}
								}catch(Exception e){
									System.out.println("企查查列表查询下一页数据获取异常{{}}==>" + e.getMessage());
								}
							}
						}
					}else{
						//数据库企业名称与企查查网站查询结果没有匹配上,则插入数据库的企业名称与pripid(主体身份代码),只会在app_legal_info(法人代表信息表)有记录
						if(index==(elements.size()-1)){
							//保存法人代表数据(是没有匹配上企查查网站的企业，插入数据库，只有企业名称(entname)和主体身份代码(entname)有值)
							saveLegalInfo(requestEntnameVal);
							countIsNull++;
							EbaseInfo ebaseInfo = new EbaseInfo(requestEntnameVal);
							crawlTableDataIsNullList.add(ebaseInfo);
						}
					}
					index++;
					continue;
				}else{
					needNextPage = false;
//					String legalName = element.select("p.m-t-xs > a.text-primary").text();
					String titleUrl = element.select("td").get(1).select("a").attr("href");
					String jyStatus = element.select("td").get(2).select("span.nstatus").text();
					System.out.println("entname==>" + entname);
					System.out.println("href==>" + titleUrl);
					System.out.println("jyStatus==>" + jyStatus);
					
					String clickTitleUrl = indexUrl + titleUrl;
					if(clickTitleUrl.indexOf("?")==-1){
						clickTitleUrl += "?companyname="+URLEncoder.encode(entname.trim()) + urlEntname + requestEncodeEntnameVal;
					}else{
						if(clickTitleUrl.indexOf("?")!=-1){
							clickTitleUrl += "&companyname="+URLEncoder.encode(entname.trim()) + urlEntname + requestEncodeEntnameVal;
						}
					}
//					clickTitleUrl = "http://www.qichacha.com/firm_4359198d09bf3237ae0465f6d40ef43a.html";
					Request clickTitleReq = this.makeRequest(clickTitleUrl, this::parseContentAsynGetUrl);
					result.addRequest(clickTitleReq);
					break;
				}
			}
		}
		return result;
	}
	
	/**
	 * 使用http再次访问链接，重新获取unique
	 * @param requestUrl
	 * @param responseBody
	 * @param urlParamMap
	 * @return
	 */
	private String getHttpForUniqueValue(String requestUrl,String responseBody,Map<String,Object> urlParamMap) {
		try{
//			responseBody = "<script>window.location.href='http://www.qichacha.com/index_verify?type=companyview&back=/firm_6849b5be77c0af252b2e55cea38b468a.html?companyname=%E4%B8%8A%E6%B5%B7%E4%B8%BD%E6%BE%B3%E5%8C%96%E5%A6%86%E5%93%81%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%E5%B9%BF%E5%B7%9E%E5%88%86%E5%85%AC%E5%8F%B8&entname=%E4%B8%8A%E6%B5%B7%E4%B8%BD%E6%BE%B3%E5%8C%96%E5%A6%86%E5%93%81%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%E5%B9%BF%E5%B7%9E%E5%88%86%E5%85%AC%E5%8F%B8';</script>";
			//判断返回响应url内容是否包含有<script>
			if(responseBody.contains("<script>") && !responseBody.contains("<!DOCTYPE html>")) {
				Constants.QCC_PAQU_STATE = "1";
				String replaceRequestUrl = responseBody.replace("<script>window.location.href='", "")
						.replace("';</script>", "");
				System.err.println("getHttpForUniqueValue的请求链接{{}}==>" + replaceRequestUrl);
//				String scriptRequestUrl = replaceRequestUrl.replace("http://www.qichacha.com/", "http://www.qichacha.com/index_verify?type=companyview&back=/");
//				String replaceRequestIndex = replaceRequestUrl.replace("http://www.qichacha.com/", "");
//				scriptRequestUrl = scriptRequestUrl + replaceRequestIndex;
				responseBody = getHttpReponseBody(replaceRequestUrl);
				if(responseBody.contains("<!DOCTYPE html>")) {
					responseBody = getHttpReponseBody(requestUrl);
				}
			}
			try{
				urlParamMap = StringUtils.urlParamToMap(requestUrl);
			}catch(Exception e1){
				System.out.println(this.getClass() + ".getHttpForUniqueValue，urlParamMap获取URL参数异常{{}}==>" + e1.getMessage());
			}
			System.out.println(responseBody);
			Document doc = Jsoup.parse(responseBody);
			Element inputElement = doc.getElementById("unique");
			return inputElement.attr("value");
		} catch (Exception e) {
			System.out.println(this.getClass() + ".getHttpForUniqueValue，使用http获取unique异常{{}}==>" + e.getMessage());
			System.err.println("使用http再次访问链接，重新获取unique......");
			if(responseBody.contains("<!DOCTYPE html>")) {
				responseBody = "<script>window.location.href='" + responseBody + "';</script>";
			}
			return getHttpForUniqueValue(requestUrl, responseBody, urlParamMap);
		}
	}
	
	/**
	 * 获取内容页异步Url
	 * @param response
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	public Result parseContentAsynGetUrl(Response response) {
		Result<List<String>> result = new Result<List<String>>();
		String requestUrl = response.getRequest().getUrl();
		System.out.println(this.getClass() + ".parseContentAsynGetUrl==>" + requestUrl);
		
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass() + ".parseContentAsynGetUrl，urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		Document doc = Jsoup.parse(response.body().toString());
		Element inputElement = doc.getElementById("unique");
		try {
			unique = inputElement.attr("value");
		} catch(Exception e) {
			if(inputElement==null) {
				System.err.println(this.getClass() + ".parseContentAsynGetUrl，unique的值{{}}==>" + unique + ",inputElement{{}}==>" + inputElement);
				//使用http再次访问链接，重新获取unique
				unique = getHttpForUniqueValue(requestUrl, response.body().toString(), urlParamMap);
			} else {
				System.err.println(this.getClass() + ".parseContentAsynGetUrl，异常信息==>" + StringUtils.getErrorInfoFromException(e));
			}
		}
		//根据企业名称查询法人代表信息表unique_id字段
		LegalInfo legalInfo = null;//shareholderService.queryEntnameByUnique(unique);
		if(legalInfo!=null){
			companyname = legalInfo.getEntname();
			companyname = URLEncoder.encode(companyname);
		}else{
			if(urlParamMap!=null){
				companyname = StringUtils.getValueForKey("companyname", urlParamMap);
				
				if(urlParamMap!=null && urlParamMap.containsKey("entname")){
					requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
				}
			}
		}
		System.out.println(this.getClass().getName() + ",unique:" + unique);
		
		//获取企查查某企业法律诉讼量
		int companyNavCount = getEntnameForSusongCount(unique);
		if(companyNavCount>0){
			//法律诉讼
			String susongUrl = indexUrl + contentAsynUrl + "unique="+unique+"&companyname="+companyname+"&tab="+tabs[1] + urlEntname + requestEncodeEntnameVal;
			Request clickSusongReq = this.makeRequest(susongUrl, this::parseContentSusong);
			result.addRequest(clickSusongReq);
		}else{
			susontCountIsNull++;
		}
		
		//获取企查查某企业基本信息
		String baseUrl = indexUrl + contentAsynUrl + "unique="+unique+"&companyname="+companyname+"&tab="+tabs[0] + urlEntname + requestEncodeEntnameVal;
		Request clickTitleReq = this.makeRequest(baseUrl, this::parseContent);
		result.addRequest(clickTitleReq);
		return result;
	}
	
	/**
	 * 通过http方式，重新获取Elements数据
	 * @param response
	 * @param elements
	 * @param requestUrl
	 * @param cssValue
	 * @return
	 */
	private Elements getHttpForElements(Response response,Elements elements, String requestUrl, String cssValue) {
		if(elements!=null && elements.size()>0){
			return elements;
		} else {
			String responseBody = response.body().toString();
			String scriptRequestUrl = requestUrl.replace("http://www.qichacha.com/", "http://www.qichacha.com/index_verify?type=companyview&back=/");
			String scriptStr = "<script>window.location.href='" + scriptRequestUrl +"';</script>";
			
			if(responseBody.contains("<script>")){
				Constants.QCC_PAQU_STATE = "1";
				responseBody = getHttpReponseBody(requestUrl);
				Document doc = Jsoup.parse(responseBody);
				elements = doc.select(cssValue);
				return elements;
			}
		}
		return elements;
	}
	
	/**
	 * 获取基本信息内容
	 * @param response
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation", "unused" })
	public Result parseContent(Response response) {
		String requestUrl = response.getRequest().getUrl();
		String responseBody = response.body().toString();
		System.out.println(this.getClass() + ".parseContent{{}}==>" + requestUrl);
//		System.out.println(this.getClass() + ".parseContent{{}}==>" + response.body());
		
		String unique = "";
		String companyname = "";
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println("urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("unique")){
			unique = StringUtils.getValueForKey("unique", urlParamMap);
		}
		
		//企业名称
		if(urlParamMap!=null && urlParamMap.containsKey("companyname")){
			companyname = StringUtils.getValueForKey("companyname", urlParamMap);
			companyname = URLDecoder.decode(companyname);
		}
		//数据库企业名称
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		
		Elements elementsPt = null;//response.body().css("div.p-t");
		if(elementsPt==null){
			//工商信息
			Elements elementsCominfo = response.body().css("div.m-t-md .row .col-md-9 .data_div #Cominfo");
			if(elementsCominfo==null || elementsCominfo.size()==0){
				elementsCominfo = response.body().css("section#Cominfo");
				
				//通过http方式，重新获取Elements数据
				elementsCominfo = getHttpForElements(response, elementsCominfo, requestUrl, "section#Cominfo");
			}
			
			if(elementsCominfo!=null && elementsCominfo.size()>0){
				//记录能匹配到数据并且可以在企查查网站上查询到工商信息数据的企业名称
				EbaseInfo matchEbaseInfo = new EbaseInfo(requestEntnameVal);
				crawlTableDataIsNotNullList.add(matchEbaseInfo);
				
				List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
				Map<String,Object> leagalInfoMap = new HashMap<String,Object>();
				
				//法人代表人名称
				String cominfoBname = elementsCominfo.select("table.ntable > tbody > tr > td > div.boss-td > div.clearfix > div.pull-left > a.bname").text();
				leagalInfoMap.put("entname", StringUtils.getReplaceStr(requestEntnameVal));
				leagalInfoMap.put("legalName", StringUtils.getReplaceStr(cominfoBname));
				//注册资本
				String regcap = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(0).select("td").get(1).text();
				//实缴资本
				String reccap = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(0).select("td").get(3).text();
				leagalInfoMap.put("regcap", StringUtils.getReplaceStr(regcap));
				leagalInfoMap.put("reccap", StringUtils.getReplaceStr(reccap));
				
				//经营状态
				String jyStatus = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(1).select("td").get(1).text();
				//成立日期
				String estdate = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(1).select("td").get(3).text();
				leagalInfoMap.put("jyStatus", StringUtils.getReplaceStr(jyStatus));
				leagalInfoMap.put("estdate", StringUtils.getReplaceStr(estdate));
				
				//注册号
				String regno = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(2).select("td").get(1).text();
				//组织机构代码
				String organizationCode = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(2).select("td").get(3).text();
				leagalInfoMap.put("regno", StringUtils.getReplaceStr(regno));
				leagalInfoMap.put("organizationCode", StringUtils.getReplaceStr(organizationCode));
				
				//纳税人识别号
				String taxpayerIdenNo = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(3).select("td").get(1).text();
				//统一社会信用代码
				String uniscid = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(3).select("td").get(3).text();
				leagalInfoMap.put("taxpayerIdenNo", StringUtils.getReplaceStr(taxpayerIdenNo));
				leagalInfoMap.put("uniscid", StringUtils.getReplaceStr(uniscid));
				
				//公司类型
				String companyType = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(4).select("td").get(1).text();
				//所属行业
				String industry = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(4).select("td").get(3).text();
				leagalInfoMap.put("companyType", StringUtils.getReplaceStr(companyType));
				leagalInfoMap.put("industry", StringUtils.getReplaceStr(industry));
				
				//核准日期
				String apprdate = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(5).select("td").get(1).text();
				//登记机关
				String regorg = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(5).select("td").get(3).text();
				leagalInfoMap.put("apprdate", StringUtils.getReplaceStr(apprdate));
				leagalInfoMap.put("regorg", StringUtils.getReplaceStr(regorg));
				
				//所属地区(中文)
				String areaCn = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(6).select("td").get(1).text();
				//所属地区(英文名)
				String areaEn = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(6).select("td").get(3).text();
				leagalInfoMap.put("areaCn", StringUtils.getReplaceStr(areaCn));
				leagalInfoMap.put("areaEn", StringUtils.getReplaceStr(areaEn));
				
				//曾用名
				String beforeUsedName = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(7).select("td").get(1).text();
				//经营方式
				String operationMode = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(7).select("td").get(3).text();
				leagalInfoMap.put("beforeUsedName", StringUtils.getReplaceStr(beforeUsedName));
				leagalInfoMap.put("operationMode", StringUtils.getReplaceStr(operationMode));
				
				//人员规模
				String personnelScale = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(8).select("td").get(1).text();
				//营业期限
				String businessTerm = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(8).select("td").get(3).text();
				leagalInfoMap.put("personnelScale", StringUtils.getReplaceStr(personnelScale));
				leagalInfoMap.put("businessTerm", StringUtils.getReplaceStr(businessTerm));
				
				//企业地址
				String entAddr = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(9).select("td").get(1).text();
				entAddr = entAddr.replace(" 查看地图", "").replace(" 附近公司", "");
				//经营范围
				String manageScope = elementsCominfo.select("table.ntable").get(1).select("tbody > tr").get(10).select("td").get(1).text();
				leagalInfoMap.put("entAddr", StringUtils.getReplaceStr(entAddr));
				leagalInfoMap.put("manageScope", StringUtils.getReplaceStr(manageScope));
				
				//转换json字符串
				String leagalInfoJson = JSON.toJSONString(leagalInfoMap);
				if(ebaseInfoList!=null && ebaseInfoList.size()>0){
					for(EbaseInfo ebaseInfo : ebaseInfoList){
						try {
							LegalInfo legalInfo = JSON.parseObject(leagalInfoJson,LegalInfo.class);
							//企业唯一id
							legalInfo.setUniqueId(unique);
							//主体身份代码
							legalInfo.setPripid(ebaseInfo.getPripid());
							//地市Id
							legalInfo.setCityId(ebaseInfo.getCityId());
							shareholderService.saveLegalInfo(legalInfo);
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				}else{
					try {
						LegalInfo legalInfo = JSON.parseObject(leagalInfoJson,LegalInfo.class);
						//企业唯一id
						legalInfo.setUniqueId(unique);
						shareholderService.saveLegalInfo(legalInfo);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}else{
				//保存法人代表数据(是没有匹配上企查查网站的企业，插入数据库，只有企业名称(entname)和主体身份代码(entname)和地市ID(cityId)有值)
				saveLegalInfo(requestEntnameVal);
				countIsNull++;
				EbaseInfo ebaseInfo = new EbaseInfo(requestEntnameVal);
				crawlTableDataIsNullList.add(ebaseInfo);
			}
			
			//股东信息
			Elements elementsSockinfo = response.body().css("div.m-t-md .row .col-md-9 .data_div_login #Sockinfo > table > tbody > tr");
			if(elementsSockinfo==null || elementsSockinfo.size()==0){
				elementsSockinfo = response.body().css("section#Sockinfo > table > tbody > tr");
				
				//通过http方式，重新获取Elements数据
				elementsSockinfo = getHttpForElements(response, elementsSockinfo, requestUrl, "section#Sockinfo > table > tbody > tr");
			}
			if(elementsSockinfo!=null && elementsSockinfo.size()>0){
				for(Element element : elementsSockinfo){
					if(element.select("th").size()>0){
						continue;
					}
					Map<String,Object> sockMap = new HashMap<String,Object>();
					//企业名称
					sockMap.put("entname", companyname);
					//股东
					if(element.select("td > a").size()>0){
						String shareholderName = element.select("td > a").get(0).text();
						sockMap.put("shareholderName", StringUtils.getReplaceStr(shareholderName));
					}
					//持股比例
					String shareholderRatio = element.select("td").get(2).text();
					sockMap.put("shareholderRatio", StringUtils.getReplaceStr(shareholderRatio));
					//认缴出资额（万元）
					String subscribedCapital = element.select("td").get(3).text();
					sockMap.put("subscribedCapital", StringUtils.getReplaceStr(subscribedCapital));
					//认缴出资日期
					String subscriptionDate = element.select("td").get(4).text();
					sockMap.put("subscriptionDate", StringUtils.getReplaceStr(subscriptionDate));
					//股东类型
					String shareholderType = element.select("td").get(5).text();
					sockMap.put("shareholderType", StringUtils.getReplaceStr(shareholderType));
					
					try{
						//转换json字符串
						String sockInfoJson = JSON.toJSONString(sockMap);
						List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
						if(ebaseInfoList!=null && ebaseInfoList.size()>0){
							for(EbaseInfo ebaseInfo : ebaseInfoList){
								Shareholder shareholder = JSON.parseObject(sockInfoJson,Shareholder.class);
								if(!StringUtils.isNullOrEmpty(unique)){
									shareholder.setUniqueId(unique);
								}
								shareholder.setPripid(ebaseInfo.getPripid());
								//地市Id
								shareholder.setCityId(ebaseInfo.getCityId());
								shareholderService.saveShareholder(shareholder);
							}
						}else{
							try{
								Shareholder shareholder = JSON.parseObject(sockInfoJson,Shareholder.class);
								if(!StringUtils.isNullOrEmpty(unique)){
									shareholder.setUniqueId(unique);
								}
								shareholderService.saveShareholder(shareholder);
							}catch(Exception e){
								System.out.println("保存股东信息异常==>" + e.getMessage());
							}
						}
					}catch(Exception e){
						System.out.println("保存股东信息或查询企业异常==>" + e.getMessage());
					}
				}
			}
			
			//主要人员
			Elements elementsMainmember = response.body().css("div.m-t-md .row .col-md-9 .data_div_login #Mainmember > table > tbody > tr");
			if(elementsMainmember==null || elementsMainmember.size()==0){
				elementsMainmember = response.body().css("section#Mainmember > table > tbody > tr");
				
				//通过http方式，重新获取Elements数据
				elementsMainmember = getHttpForElements(response, elementsMainmember, requestUrl, "section#Mainmember > table > tbody > tr");
			}
			if(elementsMainmember!=null && elementsMainmember.size()>0){
				for(Element element : elementsMainmember){
					if(element.select("th").size()>0){
						continue;
					}
					
					Map<String,Object> mainMemberMap = new HashMap<String,Object>();
					//企业名称
					mainMemberMap.put("entname", companyname);
					//姓名
					if(element.select("td > a").size()>0){
						String personnelName = element.select("td > a").get(0).text();
						mainMemberMap.put("personnelName", StringUtils.getReplaceStr(personnelName));
					}
					//职务
					String post = element.select("td").get(2).text();
					mainMemberMap.put("post", StringUtils.getReplaceStr(post));
					
					//转换json字符串
					String mainMemberJson = JSON.toJSONString(mainMemberMap);
					List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
					if(ebaseInfoList!=null && ebaseInfoList.size()>0){
						for(EbaseInfo ebaseInfo : ebaseInfoList){
							//保存主要人员
							MainPersonnel mainPersonnel = JSON.parseObject(mainMemberJson,MainPersonnel.class);
							if(!StringUtils.isNullOrEmpty(unique)){
								mainPersonnel.setUniqueId(unique);
							}
							mainPersonnel.setPripid(ebaseInfo.getPripid());
							//地市Id
							mainPersonnel.setCityId(ebaseInfo.getCityId());
							try {
								//保存主要人员
								shareholderService.saveMainPersonnel(mainPersonnel);
							} catch (Exception e) {
								e.printStackTrace();
							}
						}
					}else{
						//保存主要人员
						MainPersonnel mainPersonnel = JSON.parseObject(mainMemberJson,MainPersonnel.class);
						if(!StringUtils.isNullOrEmpty(unique)){
							mainPersonnel.setUniqueId(unique);
						}
						try {
							//保存主要人员
							shareholderService.saveMainPersonnel(mainPersonnel);
						} catch (Exception e) {
							e.printStackTrace();
						}
					}
				}
			}
			
			//企业图谱数据获取
			if(!StringUtils.isNullOrEmpty(requestUrl)){
				try{
					String cmsAsynUrl = indexUrl + contentBusinessAsynUrl + "?keyNo=" + unique;
					//返回响应url内容
					String jsonStr = getHttpForJsonData(cmsAsynUrl,requestEntnameVal);
					if(!StringUtils.isNullOrEmpty(jsonStr)){
						try{
							JSONObject json = JSONObject.parseObject(jsonStr);
							String status = json.getString("Status");
							if(json.containsKey("Status") && "200".equals(status)){
								//解析json数据并保存企业图谱数据入库
								saveEnterpriseProfileData(cmsAsynUrl,jsonStr,unique,companyname,requestEntnameVal);
							}else{
								System.err.println("企业图谱Status状态值非200，状态值为{{}}==>" + status + "，企业名称{{}}==>" + companyname + "，json串{{}}==>" + jsonStr);
							}
						}catch(Exception e){
							System.out.println("处理企业图谱数据异常{{}}==>" + StringUtils.getErrorInfoFromException(e));
						}
					}
				}catch(Exception e){
					System.out.println("企业图谱解析json数据异常{{}}==>" + e.getMessage());
				}
			}
			
			//股权结构数据获取
			if(!StringUtils.isNullOrEmpty(requestUrl)){
				try{
					String cmsAsynUrl = indexUrl + contentCmsAsynUrl + "?keyNo=" + unique;
					//返回响应url内容
					String jsonStr = getHttpForJsonData(cmsAsynUrl,requestEntnameVal);
					if(!StringUtils.isNullOrEmpty(jsonStr)){
						try{
							JSONObject json = JSONObject.parseObject(jsonStr);
							String status = json.getString("Status");
							if(json.containsKey("Status") && "200".equals(status)){
								//解析json数据并保存股权结构数据入库
								saveStockStructureData(cmsAsynUrl,jsonStr,unique,companyname,requestEntnameVal);
							}else{
								System.err.println("Status状态值非200，状态值为{{}}==>" + status + "，企业名称{{}}==>" + companyname + "，json串{{}}==>" + jsonStr);
							}
						}catch(Exception e){
							System.out.println("处理股权数据异常{{}}==>" + StringUtils.getErrorInfoFromException(e));
						}
						++handleCount;
					}
				}catch(Exception e){
					System.out.println("解析json数据异常{{}}==>" + e.getMessage());
				}
			}
			
			System.out.println("开始处理并验证数据结果。。。。。。");
			//处理并验证数据结果
			handleDataResult();
			System.out.println("完成处理并验证数据结果。。。。。。");
		}else{
			try {
				System.out.println("休眠10000毫秒！！！");
				Thread.sleep(10000);
				System.out.println("休眠后，再次调用" + this.getClass().getName());
				parse(response);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		return result;
	}
	
	/**
	 * 获取http协议返回的json数据
	 * @param cmsAsynUrl
	 * @param requestEntnameVal
	 * @return
	 */
	private String getHttpForJsonData(String cmsAsynUrl,String requestEntnameVal){
		//返回响应url内容
		String jsonStr = getHttpReponseBody(cmsAsynUrl);
		if(!StringUtils.isNullOrEmpty(jsonStr)){
			try{
				JSONObject.parseObject(jsonStr);
				return jsonStr;
			}catch(Exception e){
//				System.out.println("获取股权json数据异常{{}}==>" + StringUtils.getErrorInfoFromException(e));
				System.err.println("获取股权json数据异常，开始重新调用getStockStructureData方法。。。。。。");
				return getHttpForJsonData(cmsAsynUrl,requestEntnameVal);
			}
		}
		return jsonStr;
	}
	
	/**
	 * 获取法律诉讼内容
	 * @param response
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	public Result parseContentSusong(Response response){
		String requestUrl = response.getRequest().getUrl();
		System.out.println(this.getClass() + ".parseContentSusong{{}}==>" + requestUrl);
		
		String unique = "";
		String companyname = "";
		String requestEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass().getName() + ",urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("unique")){
			unique = StringUtils.getValueForKey("unique", urlParamMap);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("companyname")){
			companyname = StringUtils.getValueForKey("companyname", urlParamMap);
			companyname = URLDecoder.decode(companyname);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEntnameVal);
		}
		Result<List<String>> result = new Result<List<String>>();
		
		//被执行人
		Elements elementsZhixinglist = response.body().css("div.m-t-md .row .col-md-9 #susong_div > #zhixinglist > table > tbody > tr");
		if(elementsZhixinglist==null || elementsZhixinglist.size()==0){
			elementsZhixinglist = response.body().css("section#zhixinglist > table > tbody > tr");
			
			//通过http方式，重新获取Elements数据
			elementsZhixinglist = getHttpForElements(response, elementsZhixinglist, requestUrl, "section#zhixinglist > table > tbody > tr");
		}
		if(elementsZhixinglist!=null && elementsZhixinglist.size()>0){
			for(Element element : elementsZhixinglist){
				if(element.select("th").size()>0 || element.select("td").size()==0){
					continue;
				}
				Map<String,Object> zhixingMap = new HashMap<String,Object>();
				//企业名称
				zhixingMap.put("entname", companyname);
				//案号
				zhixingMap.put("caseNo", StringUtils.getReplaceStr(element.select("td").get(1).text()));
				//立案时间
				zhixingMap.put("filingTime", StringUtils.getReplaceStr(element.select("td").get(2).text()));
				//执行法院
				zhixingMap.put("courtExecution", StringUtils.getReplaceStr(element.select("td").get(3).text()));
				//执行标的
				zhixingMap.put("executes", StringUtils.getReplaceStr(element.select("td").get(4).text()));
				
				try{
					List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
					if(ebaseInfoList!=null && ebaseInfoList.size()>0){
						for(EbaseInfo ebaseInfo : ebaseInfoList){
							zhixingMap.put("uniqueId", unique);
							zhixingMap.put("pripid", ebaseInfo.getPripid());
							//转换json字符串
							String susongJson = JSON.toJSONString(zhixingMap);
							ExecutorInfo executorInfo = JSON.parseObject(susongJson,ExecutorInfo.class);
							System.out.println("被执行人json数据输出{{}}==>" + executorInfo);
							shareholderService.saveExecutorInfo(executorInfo);
						}
					}else{
						try{
							zhixingMap.put("uniqueId", unique);
							//转换json字符串
							String susongJson = JSON.toJSONString(zhixingMap);
							ExecutorInfo executorInfo = JSON.parseObject(susongJson,ExecutorInfo.class);
							System.out.println("被执行人json数据输出{{}}==>" + executorInfo);
							shareholderService.saveExecutorInfo(executorInfo);
						}catch(Exception e){
							System.out.println("保存法律诉讼被执行人信息异常==>" + e.getMessage());
						}
					}
				}catch(Exception e){
					System.out.println("保存法律诉讼被执行人或查询企业异常==>" + e.getMessage());
				}
			}
		}
		
		//裁判文书
		parseWenshuContent(response);
		
		//法院公告
		parseGonggaoContent(response);
		
		//开庭公告
		parseNoticeContent(response);
		
		susontCount++;
		return result;
	}
	
	/**
	 * 解析json数据并保存股权结构数据入库
	 * @param jsonStr
	 */
	private void saveStockStructureData(String cmsAsynUrl,String jsonStr,String unique,String entname,String requestEntnameVal){
		String resultJson = "";
		boolean isChildren = false;
		try {
			JSONObject json = JSONObject.parseObject(jsonStr);
			if(json.containsKey("Result")){
				resultJson = json.getString("Result");
			}else{
				resultJson = json.getString("Children");
			}
			JSONObject resultJsonObject = JSONObject.parseObject(resultJson);
			StockStructureInfo stockStructureInfo = null;
			List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
			if(ebaseInfoList!=null && ebaseInfoList.size()>0){
				for(EbaseInfo ebaseInfo : ebaseInfoList){
					stockStructureInfo = JSON.parseObject(resultJson, StockStructureInfo.class);
					
					if(!StringUtils.isNullOrEmpty(unique)){
						stockStructureInfo.setUniqueId(unique);
					}
					stockStructureInfo.setPripid(ebaseInfo.getPripid());
					//企业名称
					stockStructureInfo.setEntname(entname);
					if(!isChildren){
						stockStructureInfo.setParentKeyNo("0");
					}else{
						stockStructureInfo.setParentKeyNo(resultJsonObject.getString("ParentKeyNo"));
					}
					//地市Id
					stockStructureInfo.setCityId(ebaseInfo.getCityId());
					System.out.println("非循环体{{}}==>json转换对象数据{{}}==>" + stockStructureInfo);
					//保存股权结构
					shareholderService.saveStockStructure(stockStructureInfo);
				}
			}else{
				stockStructureInfo = JSON.parseObject(resultJson, StockStructureInfo.class);
				
				if(!StringUtils.isNullOrEmpty(unique)){
					stockStructureInfo.setUniqueId(unique);
				}
				//企业名称
				stockStructureInfo.setEntname(entname);
				if(!isChildren){
					stockStructureInfo.setParentKeyNo("0");
				}else{
					stockStructureInfo.setParentKeyNo(resultJsonObject.getString("ParentKeyNo"));
				}
				System.out.println("非循环体{{}}==>json转换对象数据{{}}==>" + stockStructureInfo);
				//保存股权结构
				shareholderService.saveStockStructure(stockStructureInfo);
			}
			
			if(resultJsonObject.containsKey("Children") && resultJsonObject.get("Children")!=null){
				JSONArray array = resultJsonObject.getJSONArray("Children");
				for (int i = 0; i < array.size(); i++) {
					JSONObject arrJsonObject = array.getJSONObject(i);
					String arrJsonStr = arrJsonObject.toJSONString();
					stockStructureInfo = JSON.parseObject(arrJsonStr, StockStructureInfo.class);
					if(!StringUtils.isNullOrEmpty(unique)){
						stockStructureInfo.setUniqueId(unique);
					}
					//企业名称
					stockStructureInfo.setEntname(entname);
					System.out.println("循环体{{}}==>json转换对象数据{{}}==>" + stockStructureInfo);
					//保存股权结构
					shareholderService.saveStockStructure(stockStructureInfo);
				    if(arrJsonObject.containsKey("Children") && (arrJsonObject.get("Children")!=null || !"null".equals(arrJsonObject.get("Children").toString()))){
				    	//解析子json数据
				    	saveStockStructureChildrenData(arrJsonObject.get("Children").toString(),unique,entname);
				    }
				}
			}
		} catch (Exception e) {
			System.err.println("io.github.biezhi.elves.spider.saveStockStructureData，解析json数据并保存股权结构数据入库异常，cmsAsynUrl链接为:" + cmsAsynUrl + "，json串为:" + jsonStr + "，异常信息{{}}==>" + StringUtils.getErrorInfoFromException(e));
			
			System.out.println("io.github.biezhi.elves.spider.saveStockStructureData，休眠5000毫秒后，重新再调用......");
			try {
				Thread.sleep(5000);
				System.out.println("io.github.biezhi.elves.spider.saveStockStructureData，已休眠5000毫秒，开始重新再调用saveStockStructureData方法===>");
				System.err.println("企业名称{{}}==>" + entname);
				//返回响应url内容
				jsonStr = getHttpReponseBody(cmsAsynUrl);
				saveStockStructureData(cmsAsynUrl,jsonStr, unique, entname, requestEntnameVal);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	/**
	 * 解析子json数据
	 * @param jsonStr
	 */
	private void saveStockStructureChildrenData(String jsonStr,String unique,String entname){
		try{
			JSONArray array = JSONArray.parseArray(jsonStr);
			if(array!=null){
				for (int i = 0; i < array.size(); i++) {
					JSONObject arrJsonObject = array.getJSONObject(i);
					String arrJsonStr = arrJsonObject.toJSONString();
					StockStructureInfo stockStructureInfo = JSON.parseObject(arrJsonStr, StockStructureInfo.class);
					if(!StringUtils.isNullOrEmpty(unique)){
						stockStructureInfo.setUniqueId(unique);
					}
					//企业名称
					stockStructureInfo.setEntname(entname);
					System.out.println("子循环体{{}}==>json转换对象数据{{}}==>" + stockStructureInfo);
					//保存股权结构
					try {
						shareholderService.saveStockStructure(stockStructureInfo);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}catch(Exception e){
			System.err.println("io.github.biezhi.elves.spider.saveStockStructureChildrenData，解析子json数据并保存股权结构数据入库异常，json串为:" + jsonStr + "{{}}==>" + StringUtils.getErrorInfoFromException(e));
			
			System.out.println("io.github.biezhi.elves.spider.saveStockStructureChildrenData，休眠5000毫秒后，重新再调用......");
			try {
				Thread.sleep(5000);
				
				System.out.println("io.github.biezhi.elves.spider.saveStockStructureChildrenData，已休眠5000毫秒，开始重新再调用saveStockStructureChildrenData方法===>");
				saveStockStructureChildrenData(jsonStr, unique, entname);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	/**
	 * 批量保存法人代表数据空数据(来源于数据库e_baseinfo)
	 */
	private void batchSaveLegalInfoIsNull(){
		int pageNumber = 1;
		//统计企业基础表空数据数量
		int countEntnameIsNull = shareholderService.countEbaseInfoEntnameIsNull();
		do{
			List<EbaseInfo> ebaseInfo = shareholderService.queryEbaseInfoEntnameIsNull(pageNumber,pageSize);
			if(ebaseInfo!=null && ebaseInfo.size()>0){
				try {
					//批量保存法人代表数据空数据(来源于数据库e_baseinfo)
					shareholderService.batchSaveLegalInfoIsNull(ebaseInfo);
				} catch (Exception e) {
					e.printStackTrace();
				}
				pageNumber++;
			}
		}while(pageNumber<=countEntnameIsNull);
	}
	
	/**
	 * 分页查询爬取列表数据
	 * @param pageNo		参数说明:页号
     * @param pageSize		参数说明:每页显示记录数
	 * @return
	 */
	@SuppressWarnings("deprecation")
	private String queryCrawlTableDataList(int pageNo, int pageSize){
		String urls = "";
		try{
			int order = 1;
			List<String> crawlTableDataPageList = shareholderService.queryAllOrByCityIdCrawlTableDataPage(pageNo,pageSize,staticCityProperty.getCityId());
			if(crawlTableDataPageList!=null && crawlTableDataPageList.size()>0){
				int index = 0;
				StringBuffer searchUrl = new StringBuffer();
				crawlTableDataCount = crawlTableDataPageList.size();
				
				crawlTableDataList = new ArrayList<EbaseInfo>();
				crawlTableDataIsNullList = new ArrayList<EbaseInfo>();
				for(String crawlTableData : crawlTableDataPageList){
					System.out.println("获取数据库企业名称{{}}==>第" + order + "个" + crawlTableData);
					order++;
					String crawlTableDataUrl = qichachaSearchUrl + URLEncoder.encode(crawlTableData.trim()) + "&entname=" + URLEncoder.encode(crawlTableData);
					
					/********************************先过滤一次当前企业名称能在企查查网站搜索到 开始******************************************************/
					//返回响应url内容
					String responseBody = getHttpReponseBody(crawlTableDataUrl);
					Document doc = Jsoup.parse(responseBody);
					Elements elements = doc.select(".row .col-md-9 #ajaxlist section.panel > table > tbody > tr > td");
					if(elements!=null && elements.size()>0){
					}else{
						try{
							//保存法人代表数据(是没有匹配上企查查网站的企业，插入数据库，只有企业名称(entname)和主体身份代码(pripid)有值)
							saveLegalInfo(crawlTableData);
							countIsNull++;
							EbaseInfo ebaseInfo = new EbaseInfo(crawlTableData);
							crawlTableDataIsNullList.add(ebaseInfo);
							continue;
						}catch(Exception e){
							System.out.println("保存法人代表数据(是没有匹配上企查查网站的企业，插入数据库，只有企业名称(entname)和主体身份代码(pripid)有值)处理数据异常{{}}==>" + e.getMessage());
						}
					}
					/********************************先过滤一次当前企业名称能在企查查网站搜索到 结束******************************************************/
					
					EbaseInfo ebaseInfo = new EbaseInfo(crawlTableData);
					crawlTableDataList.add(ebaseInfo);
					
					searchUrl.append(crawlTableDataUrl);
					if(index!=(crawlTableDataPageList.size()-1)){
						searchUrl.append(splitString);
					}
					index++;
				}
				urls = searchUrl.toString();
			}else{
				System.out.println("没有获取到数据{{}}==>休眠10000毫秒!!!");
				try{
					Thread.sleep(10000);
					//分页查询爬取列表数据
					queryCrawlTableDataList(pageNo, pageSize);
					System.out.println("再次获取到数据{{}}==>" + this.getClass().getName());
				}catch(Exception e){}
			}
		}catch(Exception e){
			System.out.println("分页查询爬取列表数据异常{{}}==>" + e.getMessage());
		}
		
		//处理并验证数据结果
		handleDataResult();
		return urls;
	}
	
	/**
	 * 保存法人代表数据(是没有匹配上企查查网站的企业，插入数据库，只有企业名称(entname)和主体身份代码(entname)有值)
	 * @param entname
	 */
	private void saveLegalInfo(String entname){
		//根据企业名称查询企业基础表数据
		List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(entname);
		if(ebaseInfoList!=null && ebaseInfoList.size()>0){
			System.err.println(this.getClass() + ".saveLegalInfo,是没有匹配上企查查网站的企业,企业名称{{}}==>" + entname + ",数量{{}}==>" + ebaseInfoList.size());
			for(EbaseInfo ebaseInfo : ebaseInfoList){
				//保存法人代表数据
				LegalInfo legalInfo = new LegalInfo();
				legalInfo.setPripid(ebaseInfo.getPripid());
				legalInfo.setEntname(entname);
				legalInfo.setCityId(ebaseInfo.getCityId());
				try {
					//保存法人代表数据
					shareholderService.saveLegalInfo(legalInfo);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			try {
				//根据企业名称更新爬取列表数据表设置is_null字段为T(意指在企查查网站没有搜索到)
				shareholderService.updateCrawlTableDataForIsNull(entname);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * 处理并验证数据结果
	 */
	private void handleDataResult(){
		//定义共要处理数据量
		int totalHandle = crawlTableDataCount;
		//定义要处理某企业法律诉讼数据量
		int totalHandleSusong = susontCount + susontCountIsNull;
		
		if(countIsNull>0){
			//要处理数据量 减去 不匹配企查查网站的企业数据量
			totalHandle = crawlTableDataCount - countIsNull;
			if(totalHandle==0){
				if(countIsNull==crawlTableDataCount){
					totalHandle = countIsNull;
				}else if(countIsNull>crawlTableDataCount){
					totalHandle = countIsNull;
				}else {
					totalHandle = crawlTableDataCount;
				}
			}
		}
		
		//判断不能匹配全数据量是否与爬取量相等，相等则将要处理量的值赋值为爬取量
		if(countIsNull==pageSize){
			handleCount = pageSize;
		}
		
		//判断处理量与要处理数据量是否相等，相等为已处理完本页的爬取数据并成功入库
		if(handleCount==totalHandle && totalHandleSusong==totalHandle){
			int dataIsNullSize = crawlTableDataIsNullList.size();
			int dataIsNotNullSize = crawlTableDataIsNotNullList.size();
			System.err.println("共处理了数据量{{}}==>" + (dataIsNullSize + dataIsNotNullSize));
			System.err.println("能匹配到企查查数据量{{}}==>" + dataIsNotNullSize);
			System.err.println("不能匹配到企查查数据量{{}}==>" + dataIsNullSize);
			try{
				//已爬取企业数据列表集合，判断是否为空
				if(crawlTableDataIsNotNullList!=null && crawlTableDataIsNotNullList.size()>0){
					System.out.println("开始批量更新爬取列表数据表，修改IS_LOAD爬取标识为T......");
					//根据企业名称批量更新爬取列表数据表，修改爬取标识为T
					shareholderService.batchUpdateCrawlTableDataForIsLoad(crawlTableDataList);
					System.out.println("结束批量更新爬取列表数据表，修改IS_LOAD爬取标识为T......");
				}
				
				//已爬取企业数据列表但不匹配企查查网站数据集合，判断是否为空
				if(crawlTableDataIsNullList!=null && crawlTableDataIsNullList.size()>0){
					System.out.println("开始批量更新爬取列表数据表，修改IS_NULL爬取标识为T......");
					//根据企业名称批量更新爬取列表数据表，修改爬取标识为T
					shareholderService.batchUpdateCrawlTableDataForIsLoad(crawlTableDataIsNullList);
					System.out.println("结束批量更新爬取列表数据表，修改IS_NULL爬取标识为T......");
				}
				
				//查询还没爬取企业列表数据
				int countNotLoad = shareholderService.countCrawlTableDataForNotLoad();
				if(countNotLoad>0){
					//还有还没爬取企业列表数据存在，执行以下操作
					
					//重新设置处理量为0
					handleCount = 0;
					//重新设置数据为空的量为0
					countIsNull = 0;
					
					//重新设置数据为空的量为0
					susontCount = 0;
					//重新设置数据为空的量为0
					susontCountIsNull = 0;
//					pageNo++;
					
					Constants.HANDLE_RUN = pageSize + 20;
					
					//开始创建企业数据备份表(表名+统计数)
					startCreateTableName();
					
					System.out.println("休眠50000毫秒......");
					try{
						Thread.sleep(50000);
					}catch(Exception e){
						
					}
					System.out.println("50000毫秒后，再次调用【开始执行爬虫企查查操作】");
					System.out.println();
					
					System.out.println(this.getClass() + ".handleDataResult，再次执行爬虫企查查操作...");
					startShareholder();
				}else{
					System.out.println("======开始执行 批量保存法人代表数据空数据(来源于数据库e_baseinfo)======");
					//批量保存法人代表数据空数据(来源于数据库e_baseinfo)
//					batchSaveLegalInfoIsNull();
					System.out.println("======结束执行 批量保存法人代表数据空数据(来源于数据库e_baseinfo)======");
					
					//已经全部爬取企业列表数据，系统自动停止
					System.out.println("已经全部爬取企业列表数据，系统自动停止！！！");
					System.exit(0);
				}
			}catch(Exception e){
				System.out.println("程序自动终止，出现异常{{}}==>" + StringUtils.getErrorInfoFromException(e));
				System.exit(0);
			}
		}
	}
	
	/**
	 * 获取裁判文书内容(分页)
	 * @param response
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	private Result parseWenshuContent(Response response){
		String requestUrl = response.getRequest().getUrl();
		System.out.println(this.getClass().getName() + "{{}}==>" + requestUrl);
//		System.out.println(this.getClass().getName() + "{{}}==>" + response.body());
		
		String unique = "";
		String entname = "";
		String companyname = "";
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass().getName() + ",urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("unique")){
			unique = StringUtils.getValueForKey("unique", urlParamMap);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("companyname")){
			companyname = StringUtils.getValueForKey("companyname", urlParamMap);
			entname = URLDecoder.decode(companyname);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		
		Elements elementsWenshulist = response.body().css("div.m-t-md .row .col-md-9 #susong_div > #wenshulist > table > tbody > tr");
		if(elementsWenshulist==null || elementsWenshulist.size()==0){
			elementsWenshulist = response.body().css("section#wenshulist > table > tbody > tr");
			
			//通过http方式，重新获取Elements数据
			elementsWenshulist = getHttpForElements(response, elementsWenshulist, requestUrl, "section#wenshulist > table > tbody > tr");
		}
		if(elementsWenshulist!=null && elementsWenshulist.size()>0){
			for(Element element : elementsWenshulist){
				if(element.select("th").size()>0 || element.select("td").size()==0){
					continue;
				}
				Map<String,Object> wenshuMap = new HashMap<String,Object>();
				//企业名称
				wenshuMap.put("entname", entname);
				//案件名称
				if(element.select("td > a").size()>0){
					wenshuMap.put("caseName", StringUtils.getReplaceStr(element.select("td > a").get(0).text()));
				}
				//发布时间
				wenshuMap.put("releaseTime", StringUtils.getReplaceStr(element.select("td").get(2).text()));
				//案件编号
				wenshuMap.put("caseNo", StringUtils.getReplaceStr(element.select("td").get(3).text()));
				//案件身份
				wenshuMap.put("caseIdentity", StringUtils.getReplaceStr(element.select("td").get(4).text()));
				//执行法院
				wenshuMap.put("courtExecution", StringUtils.getReplaceStr(element.select("td").get(5).text()));
				
				try{
					List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
					if(ebaseInfoList!=null && ebaseInfoList.size()>0){
						for(EbaseInfo ebaseInfo : ebaseInfoList){
							wenshuMap.put("uniqueId", unique);
							wenshuMap.put("pripid", ebaseInfo.getPripid());
							//转换json字符串
							String wenshuJson = JSON.toJSONString(wenshuMap);
							RefereeDoc refereeDoc = JSON.parseObject(wenshuJson,RefereeDoc.class);
							System.out.println(JSON.toJSON(refereeDoc));
							shareholderService.saveRefereeDoc(refereeDoc);
						}
					}else{
						try{
							wenshuMap.put("uniqueId", unique);
							//转换json字符串
							String wenshuJson = JSON.toJSONString(wenshuMap);
							RefereeDoc refereeDoc = JSON.parseObject(wenshuJson,RefereeDoc.class);
							System.out.println(JSON.toJSON(refereeDoc));
							shareholderService.saveRefereeDoc(refereeDoc);
						}catch(Exception e){
							System.out.println("保存法律诉讼被裁判文书信息异常==>" + e.getMessage());
						}
					}
				}catch(Exception e){
					System.out.println("保存法律诉讼裁判文书或查询企业异常==>" + e.getMessage());
				}
			}
			
			// 获取下一页 URL
			Elements nextEl = response.body().css("#wenshulist > div > .text-right > ul.pagination > li");
			if (null != nextEl && nextEl.size() > 0) {
				try{
					String href = "";
					String hrefText = "";
					for(Element element : nextEl){
						hrefText = element.select("a").text();
						if(">".equals(hrefText)){
							href = element.select("#ajaxpage").attr("href");
							break;
						}else{
							continue;
						}
					}
					if(">".equals(hrefText)){
						String nextPageNoStr = href.replace("javascript:getTabList(", "").replace("\"susong\",\"wenshu\")", "").replace(",", "");
						int nextPageNo = Integer.parseInt(nextPageNoStr);
						String nextPageUrl = indexUrl + contentAsynUrl + "unique="+unique+"&companyname="+companyname + "&p=" +nextPageNo +"&tab="+tabs[1] + "&box=wenshu" + urlEntname + requestEncodeEntnameVal;
						System.out.println("nextPageUrl{{}}==>" + nextPageUrl);
						//返回响应url内容
						String responseBody = getHttpReponseBody(nextPageUrl);
						//获取裁判文书每页内容
						parseWenshuContentPage(nextPageUrl, responseBody);
					}
					
//					Request nextReq = this.makeRequest(nextPageUrl, this::parseWenshuContent);
//					result.addRequest(nextReq);
				}catch(Exception e){
					System.out.println("裁判文书下一页数据获取异常{{}}==>" + e.getMessage());
				}
			}
		}
		return result;
	}
	
	/**
	 * 获取裁判文书每页内容
	 * @param requestUrl
	 * @param responseBodyContent
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	private Result parseWenshuContentPage(String requestUrl,String responseBodyContent){
		System.out.println(this.getClass().getName() + "{{}}==>" + requestUrl);
//		System.out.println(this.getClass().getName() + "{{}}==>" + responseBodyContent);
		
		int pageNo = 0;
		String unique = "";
		String entname = "";
		String companyname = "";
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass().getName() + ",urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("unique")){
			unique = StringUtils.getValueForKey("unique", urlParamMap);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("companyname")){
			companyname = StringUtils.getValueForKey("companyname", urlParamMap);
			entname = URLDecoder.decode(companyname);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("p")){
			String pageNoStr = StringUtils.getValueForKey("p", urlParamMap);
			pageNo = Integer.parseInt(pageNoStr);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		Document doc = Jsoup.parse(responseBodyContent);
		
		Elements elementsWenshulist = doc.select(".row .col-md-9 #ajaxlist section.panel > table > tbody > tr > td");
		if(elementsWenshulist==null || elementsWenshulist.size()==0){
			elementsWenshulist = doc.select("section#wenshulist > table > tbody > tr");
		}
		if(elementsWenshulist==null || elementsWenshulist.size()==0){
			elementsWenshulist = doc.select("table.ntable > tbody > tr");
		}
		if(elementsWenshulist!=null && elementsWenshulist.size()>0){
			for(Element element : elementsWenshulist){
				if(element.select("th").size()>0 || element.select("td").size()==0){
					continue;
				}
				Map<String,Object> wenshuMap = new HashMap<String,Object>();
				//企业名称
				wenshuMap.put("entname", entname);
				//案件名称
				if(element.select("td > a").size()>0){
					wenshuMap.put("caseName", StringUtils.getReplaceStr(element.select("td > a").get(0).text()));
				}
				//发布时间
				wenshuMap.put("releaseTime", StringUtils.getReplaceStr(element.select("td").get(2).text()));
				//案件编号
				wenshuMap.put("caseNo", StringUtils.getReplaceStr(element.select("td").get(3).text()));
				//案件身份
				wenshuMap.put("caseIdentity", StringUtils.getReplaceStr(element.select("td").get(4).text()));
				//执行法院
				wenshuMap.put("courtExecution", StringUtils.getReplaceStr(element.select("td").get(5).text()));
				try{
					List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
					if(ebaseInfoList!=null && ebaseInfoList.size()>0){
						for(EbaseInfo ebaseInfo : ebaseInfoList){
							wenshuMap.put("uniqueId", unique);
							wenshuMap.put("pripid", ebaseInfo.getPripid());
							//转换json字符串
							String wenshuJson = JSON.toJSONString(wenshuMap);
							RefereeDoc refereeDoc = JSON.parseObject(wenshuJson,RefereeDoc.class);
							System.out.println("第" + pageNo + "页，裁判文书json数据输出{{}}==>" + refereeDoc);
							shareholderService.saveRefereeDoc(refereeDoc);
						}
					}else{
						try{
							wenshuMap.put("uniqueId", unique);
							//转换json字符串
							String wenshuJson = JSON.toJSONString(wenshuMap);
							RefereeDoc refereeDoc = JSON.parseObject(wenshuJson,RefereeDoc.class);
							System.out.println("第" + pageNo + "页，裁判文书json数据输出{{}}==>" + refereeDoc);
							shareholderService.saveRefereeDoc(refereeDoc);
						}catch(Exception e){
							System.out.println("保存法律诉讼被裁判文书信息异常==>" + e.getMessage());
						}
					}
				}catch(Exception e){
					System.out.println("保存法律诉讼裁判文书或查询企业异常==>" + e.getMessage());
				}
			}
			
			// 获取下一页 URL
			Elements nextEl = doc.select("#wenshulist > div > .text-right > ul.pagination > li > a");
			if(nextEl==null || nextEl.size()==0){
				nextEl = doc.select("div > .text-right > ul.pagination > li > a");
			}
			if (null != nextEl && nextEl.size() > 0) {
				try{
					String href = "";
					String hrefText = "";
//					String hrefText = nextEl.last().getElementById("ajaxpage").text();
					for(Element element : nextEl){
						hrefText = element.select("a").text();
						if(">".equals(hrefText)){
							href = element.select("#ajaxpage").attr("href");
							break;
						}else{
							continue;
						}
					}
					if(">".equals(hrefText)){
						String nextPageNoStr = href.replace("javascript:getTabList(", "").replace("\"susong\",\"wenshu\")", "").replace(",", "");
						int nextPageNo = Integer.parseInt(nextPageNoStr);
						String nextPageUrl = indexUrl + contentAsynUrl + "unique="+unique+"&companyname="+companyname + "&p=" +nextPageNo +"&tab="+tabs[1] + "&box=wenshu" + urlEntname + requestEncodeEntnameVal;
						System.out.println("nextPageUrl{{}}==>" + nextPageUrl);
						//返回响应url内容
						String responseBody = getHttpReponseBody(nextPageUrl);
						parseWenshuContentPage(nextPageUrl, responseBody);
					}
				}catch(Exception e){
					System.out.println("裁判文书下一页数据获取异常{{}}==>" + e.getMessage());
				}
			}
		}
		return result;
	}
	
	/**
	 * 获取法院公告内容(分页)
	 * @param response
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	private Result parseGonggaoContent(Response response){
		String requestUrl = response.getRequest().getUrl();
		System.out.println(this.getClass() + ".parseGonggaoContent{{}}==>" + requestUrl);
//		System.out.println(this.getClass() + ".parseGonggaoContent{{}}==>" + response.body());
		
		String unique = "";
		String entname = "";
		String companyname = "";
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass().getName() + ",urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("unique")){
			unique = StringUtils.getValueForKey("unique", urlParamMap);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("companyname")){
			companyname = StringUtils.getValueForKey("companyname", urlParamMap);
			entname = URLDecoder.decode(companyname);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		Elements elementsGonggaolist = response.body().css("div.m-t-md .row .col-md-9 #susong_div > #gonggaolist > table > tbody > tr");
		if(elementsGonggaolist==null || elementsGonggaolist.size()==0){
			elementsGonggaolist = response.body().css("section#gonggaolist > table > tbody > tr");
			
			//通过http方式，重新获取Elements数据
			elementsGonggaolist = getHttpForElements(response, elementsGonggaolist, requestUrl, "section#gonggaolist > table > tbody > tr");
		}
		if(elementsGonggaolist!=null && elementsGonggaolist.size()>0){
			for(Element element : elementsGonggaolist){
				if(element.select("th").size()>0 || element.select("td").size()==0){
					continue;
				}
				Map<String,Object> gonggaoMap = new HashMap<String,Object>();
				//企业名称
				gonggaoMap.put("entname", entname);
				//当事人
				gonggaoMap.put("party", StringUtils.getReplaceStr(element.select("td").get(1).text()));
				//公告类型
				gonggaoMap.put("noticeType", StringUtils.getReplaceStr(element.select("td").get(2).text()));
				//公告人
				gonggaoMap.put("noticeMan", StringUtils.getReplaceStr(element.select("td").get(3).text()));
				//刊登时间
				gonggaoMap.put("publishTime", StringUtils.getReplaceStr(element.select("td").get(4).text()));
				
				try{
					List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
					if(ebaseInfoList!=null && ebaseInfoList.size()>0){
						for(EbaseInfo ebaseInfo : ebaseInfoList){
							gonggaoMap.put("uniqueId", unique);
							gonggaoMap.put("pripid", ebaseInfo.getPripid());
							//转换json字符串
							String gonggaoJson = JSON.toJSONString(gonggaoMap);
							NoticeCourt noticeCourt = JSON.parseObject(gonggaoJson,NoticeCourt.class);
							System.out.println("法院公告json数据输出{{}}==>" + noticeCourt);
							shareholderService.saveNoticeCourt(noticeCourt);
						}
					}else{
						try{
							gonggaoMap.put("uniqueId", unique);
							//转换json字符串
							String gonggaoJson = JSON.toJSONString(gonggaoMap);
							NoticeCourt noticeCourt = JSON.parseObject(gonggaoJson,NoticeCourt.class);
							System.out.println("法院公告json数据输出{{}}==>" + noticeCourt);
							shareholderService.saveNoticeCourt(noticeCourt);
						}catch(Exception e){
							System.out.println("保存法律诉讼法院公告信息异常==>" + e.getMessage());
						}
					}
				}catch(Exception e){
					System.out.println("保存法律诉讼法院公告或查询企业异常==>" + e.getMessage());
				}
			}
			
			// 获取下一页 URL
			Elements nextEl = response.body().css("#gonggaolist > div > .text-right > ul.pagination > li");
			if (null != nextEl && nextEl.size() > 0) {
				try{
					String href = "";
					String hrefText = "";
					for(Element element : nextEl){
						hrefText = element.select("a").text();
						if(">".equals(hrefText)){
							href = element.select("#ajaxpage").attr("href");
							break;
						}else{
							continue;
						}
					}
					if(">".equals(hrefText)){
						String nextPageNoStr = href.replace("javascript:getTabList(", "").replace("\"susong\",\"gonggao\")", "").replace(",", "");
						int nextPageNo = Integer.parseInt(nextPageNoStr);
						String nextPageUrl = indexUrl + contentAsynUrl + "unique="+unique+"&companyname="+companyname + "&p=" +nextPageNo +"&tab="+tabs[1] + "&box=gonggao" + urlEntname + requestEncodeEntnameVal;
						System.out.println("nextPageUrl{{}}==>" + nextPageUrl);
						//返回响应url内容
						String responseBody = getHttpReponseBody(nextPageUrl);
						//获取法院公告每页内容
						parseGonggaoContentPage(nextPageUrl, responseBody);
					}
				}catch(Exception e){
					System.out.println("法院公告下一页数据获取异常{{}}==>" + e.getMessage());
				}
			}
		}
		return result;
	}
	
	/**
	 * 获取法院公告每页内容
	 * @param requestUrl
	 * @param responseBodyContent
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	private Result parseGonggaoContentPage(String requestUrl,String responseBodyContent){
		System.out.println(this.getClass().getName() + "{{}}==>" + requestUrl);
//		System.out.println(this.getClass().getName() + "{{}}==>" + responseBodyContent);
		
		int pageNo = 0;
		String unique = "";
		String entname = "";
		String companyname = "";
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass().getName() + ",urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("unique")){
			unique = StringUtils.getValueForKey("unique", urlParamMap);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("companyname")){
			companyname = StringUtils.getValueForKey("companyname", urlParamMap);
			entname = URLDecoder.decode(companyname);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("p")){
			String pageNoStr = StringUtils.getValueForKey("p", urlParamMap);
			pageNo = Integer.parseInt(pageNoStr);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		Document doc = Jsoup.parse(responseBodyContent);
		
		Elements elementsGonggaolist = doc.select("div.m-t-md .row .col-md-9 #susong_div > #gonggaolist > table > tbody > tr");
		if(elementsGonggaolist==null || elementsGonggaolist.size()==0){
			elementsGonggaolist = doc.select("section#gonggaolist > table > tbody > tr");
		}
		if(elementsGonggaolist==null || elementsGonggaolist.size()==0){
			elementsGonggaolist = doc.select("table.ntable > tbody > tr");
		}
		if(elementsGonggaolist!=null && elementsGonggaolist.size()>0){
			for(Element element : elementsGonggaolist){
				if(element.select("th").size()>0 || element.select("td").size()==0){
					continue;
				}
				Map<String,Object> gonggaoMap = new HashMap<String,Object>();
				//企业名称
				gonggaoMap.put("entname", entname);
				//当事人
				gonggaoMap.put("party", StringUtils.getReplaceStr(element.select("td").get(1).text()));
				//公告类型
				gonggaoMap.put("noticeType", StringUtils.getReplaceStr(element.select("td").get(2).text()));
				//公告人
				gonggaoMap.put("noticeMan", StringUtils.getReplaceStr(element.select("td").get(3).text()));
				//刊登时间
				gonggaoMap.put("publishTime", StringUtils.getReplaceStr(element.select("td").get(4).text()));
				
				try{
					List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
					if(ebaseInfoList!=null && ebaseInfoList.size()>0){
						for(EbaseInfo ebaseInfo : ebaseInfoList){
							gonggaoMap.put("uniqueId", unique);
							gonggaoMap.put("pripid", ebaseInfo.getPripid());
							//转换json字符串
							String gonggaoJson = JSON.toJSONString(gonggaoMap);
							NoticeCourt noticeCourt = JSON.parseObject(gonggaoJson,NoticeCourt.class);
							System.out.println("第" + pageNo + "页，法院公告json数据输出{{}}==>" + noticeCourt);
							shareholderService.saveNoticeCourt(noticeCourt);
						}
					}else{
						try{
							gonggaoMap.put("uniqueId", unique);
							//转换json字符串
							String gonggaoJson = JSON.toJSONString(gonggaoMap);
							NoticeCourt noticeCourt = JSON.parseObject(gonggaoJson,NoticeCourt.class);
							System.out.println("第" + pageNo + "页，法院公告json数据输出{{}}==>" + noticeCourt);
							shareholderService.saveNoticeCourt(noticeCourt);
						}catch(Exception e){
							System.out.println("保存法律诉讼法院公告信息异常==>" + e.getMessage());
						}
					}
				}catch(Exception e){
					System.out.println("保存法律诉讼法院公告或查询企业异常==>" + e.getMessage());
				}
			}
			
			// 获取下一页 URL
			Elements nextEl = doc.select("#gonggaolist > div > .text-right > ul.pagination > li > a");
			if(nextEl==null || nextEl.size()==0){
				nextEl = doc.select("div > .text-right > ul.pagination > li > a");
			}
			if (null != nextEl && nextEl.size() > 0) {
				try{
					String href = "";
					String hrefText = "";
//					String hrefText = nextEl.last().getElementById("ajaxpage").text();
					for(Element element : nextEl){
						hrefText = element.select("a").text();
						if(">".equals(hrefText)){
							href = element.select("#ajaxpage").attr("href");
							break;
						}else{
							continue;
						}
					}
					if(">".equals(hrefText)){
						String nextPageNoStr = href.replace("javascript:getTabList(", "").replace("\"susong\",\"gonggao\")", "").replace(",", "");
						int nextPageNo = Integer.parseInt(nextPageNoStr);
						String nextPageUrl = indexUrl + contentAsynUrl + "unique="+unique+"&companyname="+companyname + "&p=" +nextPageNo +"&tab="+tabs[1] + "&box=gonggao" + urlEntname + requestEncodeEntnameVal;
						System.out.println("nextPageUrl{{}}==>" + nextPageUrl);
						//返回响应url内容
						String responseBody = getHttpReponseBody(nextPageUrl);
						parseGonggaoContentPage(nextPageUrl, responseBody);
					}
				}catch(Exception e){
					System.out.println("法院公告下一页数据获取异常{{}}==>" + e.getMessage());
				}
			}
		}
		return result;
	}
	
	/**
	 * 获取开庭公告内容(分页)
	 * @param response
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	private Result parseNoticeContent(Response response){
		String requestUrl = response.getRequest().getUrl();
		System.out.println(this.getClass().getName() + "{{}}==>" + requestUrl);
//		System.out.println(this.getClass().getName() + "{{}}==>" + response.body());
		
		String unique = "";
		String entname = "";
		String companyname = "";
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass().getName() + ",urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("unique")){
			unique = StringUtils.getValueForKey("unique", urlParamMap);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("companyname")){
			companyname = StringUtils.getValueForKey("companyname", urlParamMap);
			entname = URLDecoder.decode(companyname);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		Elements elementsNoticelist = response.body().css("div.m-t-md .row .col-md-9 #susong_div > #noticelist > table > tbody > tr");
		if(elementsNoticelist==null || elementsNoticelist.size()==0){
			elementsNoticelist = response.body().css("section#noticelist > table > tbody > tr");
			
			//通过http方式，重新获取Elements数据
			elementsNoticelist = getHttpForElements(response, elementsNoticelist, requestUrl, "section#noticelist > table > tbody > tr");
		}
		if(elementsNoticelist!=null && elementsNoticelist.size()>0){
			for(Element element : elementsNoticelist){
				if(element.select("th").size()>0 || element.select("td").size()==0){
					continue;
				}
				Map<String,Object> noticeMap = new HashMap<String,Object>();
				//企业名称
				noticeMap.put("entname", entname);
				//案号
				if(element.select("td > a").size()>0){
					noticeMap.put("caseNo", StringUtils.getReplaceStr(element.select("td > a").get(0).text()));
				}
				//开庭日期
				noticeMap.put("courtDate", StringUtils.getReplaceStr(element.select("td").get(2).text()));
				//案由
				noticeMap.put("causeAction", StringUtils.getReplaceStr(element.select("td").get(3).text()));
				//公诉人/原告/上诉人/申请人
				noticeMap.put("plaintiff", StringUtils.getReplaceStr(element.select("td").get(4).text()));
				//被告人/被告/被上诉人/被申请人
				noticeMap.put("defendant", StringUtils.getReplaceStr(element.select("td").get(5).text()));
				try{
					List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
					if(ebaseInfoList!=null && ebaseInfoList.size()>0){
						for(EbaseInfo ebaseInfo : ebaseInfoList){
							noticeMap.put("uniqueId", unique);
							noticeMap.put("pripid", ebaseInfo.getPripid());
							//转换json字符串
							String noticeJson = JSON.toJSONString(noticeMap);
							BulletinCourt bulletinCourt = JSON.parseObject(noticeJson,BulletinCourt.class);
							System.out.println("开庭公告json数据输出{{}}==>" + bulletinCourt);
							shareholderService.saveBulletinCourt(bulletinCourt);
						}
					}else{
						try{
							noticeMap.put("uniqueId", unique);
							//转换json字符串
							String noticeJson = JSON.toJSONString(noticeMap);
							BulletinCourt bulletinCourt = JSON.parseObject(noticeJson,BulletinCourt.class);
							System.out.println("开庭公告json数据输出{{}}==>" + bulletinCourt);
							shareholderService.saveBulletinCourt(bulletinCourt);
						}catch(Exception e){
							System.out.println("保存法律诉讼开庭公告信息异常==>" + e.getMessage());
						}
					}
				}catch(Exception e){
					System.out.println("保存法律诉讼开庭公告或查询企业异常==>" + e.getMessage());
				}
			}
		}
			
		// 获取下一页 URL
		Elements nextEl = response.body().css("#noticelist > div > .text-right > ul.pagination > li");
		if (null != nextEl && nextEl.size() > 0) {
			try{
				String href = "";
				String hrefText = "";
				for(Element element : nextEl){
					hrefText = element.select("a").text();
					if(">".equals(hrefText)){
						href = element.select("#ajaxpage").attr("href");
						break;
					}else{
						continue;
					}
				}
				if(">".equals(hrefText)){
					String nextPageNoStr = href.replace("javascript:getTabList(", "").replace("\"susong\",\"notice\")", "").replace(",", "");
					int nextPageNo = Integer.parseInt(nextPageNoStr);
					String nextPageUrl = indexUrl + contentAsynUrl + "unique="+unique+"&companyname="+companyname + "&p=" +nextPageNo +"&tab="+tabs[1] + "&box=notice" + urlEntname + requestEncodeEntnameVal;
					System.out.println("nextPageUrl{{}}==>" + nextPageUrl);
					//返回响应url内容
					String responseBody = getHttpReponseBody(nextPageUrl);
					//获取开庭公告每页内容
					parseNoticeContentPage(nextPageUrl, responseBody);
				}
			}catch(Exception e){
				System.out.println("开庭公告下一页数据获取异常{{}}==>" + e.getMessage());
			}
		}
		return result;
	}
	
	/**
	 * 获取开庭公告每页内容
	 * @param requestUrl
	 * @param responseBodyContent
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "deprecation" })
	private Result parseNoticeContentPage(String requestUrl,String responseBodyContent){
		System.out.println(this.getClass().getName() + "{{}}==>" + requestUrl);
//		System.out.println(this.getClass().getName() + "{{}}==>" + responseBodyContent);
		
		int pageNo = 0;
		String unique = "";
		String entname = "";
		String companyname = "";
		String requestEntnameVal = "";
		String requestEncodeEntnameVal = "";
		Map<String,Object> urlParamMap = null;
		try{
			urlParamMap = StringUtils.urlParamToMap(requestUrl);
		}catch(Exception e){
			System.out.println(this.getClass().getName() + ",urlParamMap获取URL参数异常{{}}==>" + e.getMessage());
		}
		if(urlParamMap!=null && urlParamMap.containsKey("unique")){
			unique = StringUtils.getValueForKey("unique", urlParamMap);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("companyname")){
			companyname = StringUtils.getValueForKey("companyname", urlParamMap);
			entname = URLDecoder.decode(companyname);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("entname")){
			requestEncodeEntnameVal = StringUtils.getValueForKey("entname", urlParamMap);
			requestEntnameVal = URLDecoder.decode(requestEncodeEntnameVal);
		}
		if(urlParamMap!=null && urlParamMap.containsKey("p")){
			String pageNoStr = StringUtils.getValueForKey("p", urlParamMap);
			pageNo = Integer.parseInt(pageNoStr);
		}
		
		Result<List<String>> result = new Result<List<String>>();
		Document doc = Jsoup.parse(responseBodyContent);
		
		Elements elementsNoticelist = doc.select("div.m-t-md .row .col-md-9 #susong_div > #noticelist > table > tbody > tr");
		if(elementsNoticelist==null || elementsNoticelist.size()==0){
			elementsNoticelist = doc.select("section#noticelist > table > tbody > tr");
		}
		if(elementsNoticelist==null || elementsNoticelist.size()==0){
			elementsNoticelist = doc.select("table.ntable > tbody > tr");
		}
		if(elementsNoticelist!=null && elementsNoticelist.size()>0){
			for(Element element : elementsNoticelist){
				if(element.select("th").size()>0 || element.select("td").size()==0){
					continue;
				}
				Map<String,Object> noticeMap = new HashMap<String,Object>();
				//企业名称
				noticeMap.put("entname", entname);
				//案号
				if(element.select("td > a").size()>0){
					noticeMap.put("caseNo", StringUtils.getReplaceStr(element.select("td > a").get(0).text()));
				}
				//开庭日期
				noticeMap.put("courtDate", StringUtils.getReplaceStr(element.select("td").get(2).text()));
				//案由
				noticeMap.put("causeAction", StringUtils.getReplaceStr(element.select("td").get(3).text()));
				//公诉人/原告/上诉人/申请人
				noticeMap.put("plaintiff", StringUtils.getReplaceStr(element.select("td").get(4).text()));
				//被告人/被告/被上诉人/被申请人
				noticeMap.put("defendant", StringUtils.getReplaceStr(element.select("td").get(5).text()));
				try{
					List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(requestEntnameVal);
					if(ebaseInfoList!=null && ebaseInfoList.size()>0){
						for(EbaseInfo ebaseInfo : ebaseInfoList){
							noticeMap.put("uniqueId", unique);
							noticeMap.put("pripid", ebaseInfo.getPripid());
							//转换json字符串
							String noticeJson = JSON.toJSONString(noticeMap);
							BulletinCourt bulletinCourt = JSON.parseObject(noticeJson,BulletinCourt.class);
							System.out.println("第" + pageNo + "页，开庭公告json数据输出{{}}==>" + bulletinCourt);
							shareholderService.saveBulletinCourt(bulletinCourt);
						}
					}else{
						try{
							noticeMap.put("uniqueId", unique);
							//转换json字符串
							String noticeJson = JSON.toJSONString(noticeMap);
							BulletinCourt bulletinCourt = JSON.parseObject(noticeJson,BulletinCourt.class);
							System.out.println("第" + pageNo + "页，开庭公告json数据输出{{}}==>" + bulletinCourt);
							shareholderService.saveBulletinCourt(bulletinCourt);
						}catch(Exception e){
							System.out.println("保存法律诉讼开庭公告信息异常==>" + e.getMessage());
						}
					}
				}catch(Exception e){
					System.out.println("保存法律诉讼开庭公告或查询企业异常==>" + e.getMessage());
				}
			}
		}
			
		// 获取下一页 URL
		Elements nextEl = doc.select("#noticelist > div > .text-right > ul.pagination > li > a");
		if(nextEl==null || nextEl.size()==0){
			nextEl = doc.select("div > .text-right > ul.pagination > li > a");
		}
		if (null != nextEl && nextEl.size() > 0) {
			try{
				String href = "";
				String hrefText = "";
				for(Element element : nextEl){
					hrefText = element.select("a").text();
					if(">".equals(hrefText)){
						href = element.select("#ajaxpage").attr("href");
						break;
					}else{
						continue;
					}
				}
				if(">".equals(hrefText)){
					String nextPageNoStr = href.replace("javascript:getTabList(", "").replace("\"susong\",\"notice\")", "").replace(",", "");
					int nextPageNo = Integer.parseInt(nextPageNoStr);
					String nextPageUrl = indexUrl + contentAsynUrl + "unique="+unique+"&companyname="+companyname + "&p=" +nextPageNo +"&tab="+tabs[1] + "&box=notice" + urlEntname + requestEncodeEntnameVal;
					System.out.println("nextPageUrl{{}}==>" + nextPageUrl);
					//返回响应url内容
					String responseBody = getHttpReponseBody(nextPageUrl);
					parseNoticeContentPage(nextPageUrl, responseBody);
				}
			}catch(Exception e){
				System.out.println("开庭公告下一页数据获取异常{{}}==>" + e.getMessage());
			}
		}
		return result;
	}
	
	/**
	 * 解析json数据并保存企业图谱数据入库
	 * @param cmsAsynUrl
	 * @param jsonStr
	 * @param unique
	 * @param entname
	 * @param requestEntnameVal
	 */
	private void saveEnterpriseProfileData(String cmsAsynUrl,String jsonStr,String unique,String entname,String requestEntnameVal){
		String resultJson = "";
		String parentKeyNo = "";
		boolean isChildren = false;
		try {
			JSONObject json = JSONObject.parseObject(jsonStr);
			if(json.containsKey("Result")){
				resultJson = json.getString("Result");
				
				JSONObject nodeJson = JSONObject.parseObject(resultJson);
				if(nodeJson.containsKey("Node")){
					resultJson = nodeJson.getString("Node");
				}
			}else{
				resultJson = json.getString("children");
			}
			JSONObject resultJsonObject = JSONObject.parseObject(resultJson);
			EnterpriseProfileInfo enterpriseProfileInfo = null;
			List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(entname);
			if(ebaseInfoList!=null && ebaseInfoList.size()>0){
				for(EbaseInfo ebaseInfo : ebaseInfoList){
					enterpriseProfileInfo = JSON.parseObject(resultJson, EnterpriseProfileInfo.class);
					
					if(!StringUtils.isNullOrEmpty(unique)){
						enterpriseProfileInfo.setUniqueId(unique);
					}
					enterpriseProfileInfo.setPripid(ebaseInfo.getPripid());
					//企业名称
					if(resultJsonObject.containsKey("name")){
						enterpriseProfileInfo.setEntname(resultJsonObject.getString("name"));
					}
					if(!isChildren){
						if(resultJsonObject.containsKey("KeyNo")){
							parentKeyNo = resultJsonObject.getString("KeyNo");
						}else{
							parentKeyNo = getKeyNoUUID();
						}
						enterpriseProfileInfo.setParentKeyNo("0");
					}else{
						enterpriseProfileInfo.setParentKeyNo(parentKeyNo);
					}
					//地市Id
					enterpriseProfileInfo.setCityId(ebaseInfo.getCityId());
					System.out.println("非循环体{{}}==>json转换对象数据{{}}==>" + enterpriseProfileInfo);
					//保存企业图谱
					shareholderService.saveEnterpriseProfileInfo(enterpriseProfileInfo);
				}
			}else{
				enterpriseProfileInfo = JSON.parseObject(resultJson, EnterpriseProfileInfo.class);
				
				if(!StringUtils.isNullOrEmpty(unique)){
					enterpriseProfileInfo.setUniqueId(unique);
				}
				//企业名称
				if(resultJsonObject.containsKey("name")){
					enterpriseProfileInfo.setEntname(resultJsonObject.getString("name"));
				}
				if(!isChildren){
					if(resultJsonObject.containsKey("KeyNo")){
						parentKeyNo = resultJsonObject.getString("KeyNo");
					}else{
						parentKeyNo = getKeyNoUUID();
					}
					enterpriseProfileInfo.setParentKeyNo("0");
				}else{
					enterpriseProfileInfo.setParentKeyNo(parentKeyNo);
				}
				System.out.println("非循环体{{}}==>json转换对象数据{{}}==>" + enterpriseProfileInfo);
				//保存企业图谱数据
				shareholderService.saveEnterpriseProfileInfo(enterpriseProfileInfo);
			}
			
			String childrenKeyNo = "";
			String childrenParentKeyNo = "";
			if(resultJsonObject.containsKey("children") && resultJsonObject.get("children")!=null){
				JSONArray array = resultJsonObject.getJSONArray("children");
				for (int i = 0; i < array.size(); i++) {
					JSONObject arrJsonObject = array.getJSONObject(i);
					String arrJsonStr = arrJsonObject.toJSONString();
					JSONObject childrenJsonObject = JSONObject.parseObject(arrJsonStr);
					enterpriseProfileInfo = JSON.parseObject(arrJsonStr, EnterpriseProfileInfo.class);
					if(!StringUtils.isNullOrEmpty(unique)){
						enterpriseProfileInfo.setUniqueId(unique);
					}
					//企业名称
					if(childrenJsonObject.containsKey("name")){
						enterpriseProfileInfo.setEntname(childrenJsonObject.getString("name"));
					}
					if(!childrenJsonObject.containsKey("KeyNo")){
						childrenKeyNo = getKeyNoUUID();
						childrenParentKeyNo = childrenKeyNo;
						enterpriseProfileInfo.setKeyNo(childrenKeyNo);
						enterpriseProfileInfo.setParentKeyNo(parentKeyNo);
					}else{
						childrenParentKeyNo = childrenJsonObject.getString("KeyNo");
						enterpriseProfileInfo.setParentKeyNo(parentKeyNo);
					}
					System.out.println("循环体{{}}==>json转换对象数据{{}}==>" + enterpriseProfileInfo);
					//保存企业图谱数据
					shareholderService.saveEnterpriseProfileInfo(enterpriseProfileInfo);
				    if(arrJsonObject.containsKey("children") && (arrJsonObject.get("children")!=null || !"null".equals(arrJsonObject.get("children").toString()))){
				    	//解析企业图谱子json数据
				    	saveEnterpriseProfileChildrenData(arrJsonObject.get("children").toString(),unique,entname,childrenParentKeyNo);
				    }
				}
			}
		} catch (Exception e) {
			System.err.println("io.github.biezhi.elves.spider.saveEnterpriseProfileData，解析json数据并保存企业图谱数据入库异常，cmsAsynUrl链接为:" + cmsAsynUrl + "，json串为:" + jsonStr + "，异常信息{{}}==>" + StringUtils.getErrorInfoFromException(e));
			
			System.out.println("io.github.biezhi.elves.spider.saveEnterpriseProfileData，休眠5000毫秒后，重新再调用......");
			try {
				Thread.sleep(5000);
				System.out.println("io.github.biezhi.elves.spider.saveEnterpriseProfileData，已休眠5000毫秒，开始重新再调用saveEnterpriseProfileData方法===>");
				System.err.println("企业名称{{}}==>" + entname);
				//返回响应url内容
				jsonStr = getHttpReponseBody(cmsAsynUrl);
				saveEnterpriseProfileData(cmsAsynUrl,jsonStr, unique, entname, requestEntnameVal);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	/**
	 * 解析企业图谱子json数据
	 * @param jsonStr
	 * @param unique
	 * @param entname
	 * @param childrenParentKeyNo
	 */
	private void saveEnterpriseProfileChildrenData(String jsonStr,String unique,String entname,String childrenParentKeyNo){
		try{
			JSONArray array = JSONArray.parseArray(jsonStr);
			if(array!=null){
				for (int i = 0; i < array.size(); i++) {
					JSONObject arrJsonObject = array.getJSONObject(i);
					String arrJsonStr = arrJsonObject.toJSONString();
					JSONObject childrenJsonObject = JSONObject.parseObject(arrJsonStr);
					
					EnterpriseProfileInfo enterpriseProfileInfo = JSON.parseObject(arrJsonStr, EnterpriseProfileInfo.class);
					if(!StringUtils.isNullOrEmpty(unique)){
						enterpriseProfileInfo.setUniqueId(unique);
					}
					//企业名称
					if(childrenJsonObject.containsKey("name")){
						enterpriseProfileInfo.setEntname(childrenJsonObject.getString("name"));
					}
					if(!childrenJsonObject.containsKey("KeyNo")){
						String childrenKeyNo = getKeyNoUUID();
						enterpriseProfileInfo.setKeyNo(childrenKeyNo);
						enterpriseProfileInfo.setParentKeyNo(childrenParentKeyNo);
					}else{
						enterpriseProfileInfo.setParentKeyNo(childrenParentKeyNo);
					}
					System.out.println("子循环体{{}}==>json转换对象数据{{}}==>" + enterpriseProfileInfo);
					try {
						//保存企业图谱数据
						shareholderService.saveEnterpriseProfileInfo(enterpriseProfileInfo);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}catch(Exception e){
			System.err.println("io.github.biezhi.elves.spider.saveEnterpriseProfileData，解析子json数据并保存企业图谱数据入库异常，json串为:" + jsonStr + "{{}}==>" + StringUtils.getErrorInfoFromException(e));
			
			System.out.println("io.github.biezhi.elves.spider.saveEnterpriseProfileData，休眠5000毫秒后，重新再调用......");
			try {
				Thread.sleep(5000);
				
				System.out.println("io.github.biezhi.elves.spider.saveEnterpriseProfileData，已休眠5000毫秒，开始重新再调用saveEnterpriseProfileData方法===>");
				saveEnterpriseProfileChildrenData(jsonStr, unique, entname, childrenParentKeyNo);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	/**
	 * 解析json数据并保存投资族谱数据入库
	 * @param cmsAsynUrl
	 * @param jsonStr
	 * @param unique
	 * @param entname
	 * @param requestEntnameVal
	 */
	private void saveFamilyInvestmentData(String cmsAsynUrl,String jsonStr,String unique,String entname,String requestEntnameVal){
		String resultJson = "";
		String parentKeyNo = "";
		boolean isChildren = false;
		try {
			JSONObject json = JSONObject.parseObject(jsonStr);
			if(json.containsKey("Result")){
				resultJson = json.getString("Result");
				
				JSONObject nodeJson = JSONObject.parseObject(resultJson);
				if(nodeJson.containsKey("Node")){
					resultJson = nodeJson.getString("Node");
				}
			}else{
				resultJson = json.getString("children");
			}
			JSONObject resultJsonObject = JSONObject.parseObject(resultJson);
			FamilyInvestmentInfo familyInvestmentInfo = null;
			List<EbaseInfo> ebaseInfoList = shareholderService.queryEbaseInfoByEntname(entname);
			if(ebaseInfoList!=null && ebaseInfoList.size()>0){
				for(EbaseInfo ebaseInfo : ebaseInfoList){
					familyInvestmentInfo = JSON.parseObject(resultJson, FamilyInvestmentInfo.class);
					
					if(!StringUtils.isNullOrEmpty(unique)){
						familyInvestmentInfo.setUniqueId(unique);
					}
					familyInvestmentInfo.setPripid(ebaseInfo.getPripid());
					//企业名称
					if(resultJsonObject.containsKey("name")){
						familyInvestmentInfo.setEntname(resultJsonObject.getString("name"));
					}
					if(!isChildren){
						if(resultJsonObject.containsKey("KeyNo")){
							parentKeyNo = resultJsonObject.getString("KeyNo");
						}else{
							parentKeyNo = getKeyNoUUID();
						}
						familyInvestmentInfo.setParentKeyNo("0");
					}else{
						familyInvestmentInfo.setParentKeyNo(parentKeyNo);
					}
					//地市Id
					familyInvestmentInfo.setCityId(ebaseInfo.getCityId());
					System.out.println("非循环体{{}}==>json转换对象数据{{}}==>" + familyInvestmentInfo);
					//保存投资族谱
					shareholderService.saveFamilyInvestmentInfo(familyInvestmentInfo);
				}
			}else{
				familyInvestmentInfo = JSON.parseObject(resultJson, FamilyInvestmentInfo.class);
				
				if(!StringUtils.isNullOrEmpty(unique)){
					familyInvestmentInfo.setUniqueId(unique);
				}
				//企业名称
				if(resultJsonObject.containsKey("name")){
					familyInvestmentInfo.setEntname(resultJsonObject.getString("name"));
				}
				if(!isChildren){
					if(resultJsonObject.containsKey("KeyNo")){
						parentKeyNo = resultJsonObject.getString("KeyNo");
					}else{
						parentKeyNo = getKeyNoUUID();
					}
					familyInvestmentInfo.setParentKeyNo("0");
				}else{
					familyInvestmentInfo.setParentKeyNo(parentKeyNo);
				}
				System.out.println("非循环体{{}}==>json转换对象数据{{}}==>" + familyInvestmentInfo);
				//保存投资族谱数据
				shareholderService.saveFamilyInvestmentInfo(familyInvestmentInfo);
			}
			
			String childrenKeyNo = "";
			String childrenParentKeyNo = "";
			if(resultJsonObject.containsKey("children") && resultJsonObject.get("children")!=null){
				JSONArray array = resultJsonObject.getJSONArray("children");
				for (int i = 0; i < array.size(); i++) {
					JSONObject arrJsonObject = array.getJSONObject(i);
					String arrJsonStr = arrJsonObject.toJSONString();
					JSONObject childrenJsonObject = JSONObject.parseObject(arrJsonStr);
					familyInvestmentInfo = JSON.parseObject(arrJsonStr, FamilyInvestmentInfo.class);
					if(!StringUtils.isNullOrEmpty(unique)){
						familyInvestmentInfo.setUniqueId(unique);
					}
					//企业名称
					if(childrenJsonObject.containsKey("name")){
						familyInvestmentInfo.setEntname(childrenJsonObject.getString("name"));
					}
					if(!childrenJsonObject.containsKey("KeyNo")){
						childrenKeyNo = getKeyNoUUID();
						childrenParentKeyNo = childrenKeyNo;
						familyInvestmentInfo.setKeyNo(childrenKeyNo);
						familyInvestmentInfo.setParentKeyNo(parentKeyNo);
					}else{
						childrenParentKeyNo = childrenJsonObject.getString("KeyNo");
						familyInvestmentInfo.setParentKeyNo(parentKeyNo);
					}
					System.out.println("循环体{{}}==>json转换对象数据{{}}==>" + familyInvestmentInfo);
					//保存投资族谱数据
					shareholderService.saveFamilyInvestmentInfo(familyInvestmentInfo);
				    if(arrJsonObject.containsKey("children") && (arrJsonObject.get("children")!=null || !"null".equals(arrJsonObject.get("children").toString()))){
				    	//解析投资族谱子json数据
				    	saveFamilyInvestmentChildrenData(arrJsonObject.get("children").toString(),unique,entname,childrenParentKeyNo);
				    }
				}
			}
		} catch (Exception e) {
			System.err.println("io.github.biezhi.elves.spider.saveFamilyInvestmentData，解析json数据并保存投资族谱数据入库异常，cmsAsynUrl链接为:" + cmsAsynUrl + "，json串为:" + jsonStr + "，异常信息{{}}==>" + StringUtils.getErrorInfoFromException(e));
			
			System.out.println("io.github.biezhi.elves.spider.saveFamilyInvestmentData，休眠5000毫秒后，重新再调用......");
			try {
				Thread.sleep(5000);
				System.out.println("io.github.biezhi.elves.spider.saveFamilyInvestmentData，已休眠5000毫秒，开始重新再调用saveFamilyInvestmentData方法===>");
				System.err.println("企业名称{{}}==>" + entname);
				//返回响应url内容
				jsonStr = getHttpReponseBody(cmsAsynUrl);
				saveFamilyInvestmentData(cmsAsynUrl,jsonStr, unique, entname, requestEntnameVal);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	/**
	 * 解析投资族谱子json数据
	 * @param jsonStr
	 * @param unique
	 * @param entname
	 * @param childrenParentKeyNo
	 */
	private void saveFamilyInvestmentChildrenData(String jsonStr,String unique,String entname,String childrenParentKeyNo){
		try{
			JSONArray array = JSONArray.parseArray(jsonStr);
			if(array!=null){
				for (int i = 0; i < array.size(); i++) {
					JSONObject arrJsonObject = array.getJSONObject(i);
					String arrJsonStr = arrJsonObject.toJSONString();
					JSONObject childrenJsonObject = JSONObject.parseObject(arrJsonStr);
					
					FamilyInvestmentInfo familyInvestmentInfo = JSON.parseObject(arrJsonStr, FamilyInvestmentInfo.class);
					if(!StringUtils.isNullOrEmpty(unique)){
						familyInvestmentInfo.setUniqueId(unique);
					}
					//企业名称
					if(childrenJsonObject.containsKey("name")){
						familyInvestmentInfo.setEntname(childrenJsonObject.getString("name"));
					}
					if(!childrenJsonObject.containsKey("KeyNo")){
						String childrenKeyNo = getKeyNoUUID();
						familyInvestmentInfo.setKeyNo(childrenKeyNo);
						familyInvestmentInfo.setParentKeyNo(childrenParentKeyNo);
					}else{
						familyInvestmentInfo.setParentKeyNo(childrenParentKeyNo);
					}
					System.out.println("子循环体{{}}==>json转换对象数据{{}}==>" + familyInvestmentInfo);
					try {
						//保存投资族谱数据
						shareholderService.saveFamilyInvestmentInfo(familyInvestmentInfo);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}catch(Exception e){
			System.err.println("io.github.biezhi.elves.spider.saveFamilyInvestmentChildrenData，解析子json数据并保存投资族谱数据入库异常，json串为:" + jsonStr + "{{}}==>" + StringUtils.getErrorInfoFromException(e));
			
			System.out.println("io.github.biezhi.elves.spider.saveFamilyInvestmentChildrenData，休眠5000毫秒后，重新再调用......");
			try {
				Thread.sleep(5000);
				
				System.out.println("io.github.biezhi.elves.spider.saveFamilyInvestmentChildrenData，已休眠5000毫秒，开始重新再调用saveFamilyInvestmentChildrenData方法===>");
				saveFamilyInvestmentChildrenData(jsonStr, unique, entname, childrenParentKeyNo);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
	}
	
	/**
	 * 获取KeyNo的uuid
	 * @return
	 */
	private String getKeyNoUUID(){
		//获取uuid
		String uuid = StringUtils.get32UUID();
		while(true){
			//将uuid作为入参，查询企业图谱表数据keyno值，是否已存在数据库中，如果存在，则重新获取，不存在，则直接返回
			int existCount = shareholderService.countEnterpriseKeyNoByUuid(uuid);
			if(existCount>0){
				//重新获取uuid
				uuid = StringUtils.get32UUID();
			}else{
				break;
			}
		}
		return uuid;
	}
	
	/**
	 * 返回响应url内容
	 * @return
	 */
	private String getHttpReponseBody(String requestUrl){
		String jsonStr = "";
		try {
			log.info("获取url内容时，先休眠5000毫秒......");
			Thread.sleep(5000);
			log.info("已休眠5000毫秒，开始获取url内容===>");
			String qccCookie = QccSelenium.reloadQccCookie(requestUrl);
//			System.out.println(this.getClass() + ".getHttpReponseBody方法，qccCookie{{}}==>" + qccCookie);
			io.github.biezhi.elves.ok.http.Response okHttpResponse;
			if(!Constants.IS_PROXY){
				okHttpResponse = FastHttpClient
						.get()
						.addHeader("cookie", qccCookie)
						.url(requestUrl)
						.build()
						.execute();
			}else{
				Proxy proxy = new Proxy(Proxy.Type.HTTP,new InetSocketAddress(Constants.PROXY_IP, Constants.PROXY_PORT));
				okHttpResponse = FastHttpClient
						.newBuilder()
						.proxy(proxy)
						.build()
						.get().addHeader("cookie", qccCookie)
						.url(requestUrl)
						.build()
						.execute();
			}
			jsonStr = okHttpResponse.string();
			if("[]".equals(jsonStr)){
				jsonStr = "";
			}
			//判断是否为json格式
			boolean isJson = StringUtils.isJsonFormat(jsonStr);
			if(!isJson){
				String scriptRequestUrl = requestUrl.replace("http://www.qichacha.com/", "http://www.qichacha.com/index_verify?type=companysearch&back=/");
				String scriptStr = "<script>window.location.href='" + scriptRequestUrl +"';</script>";
				
				if(scriptStr.equals(jsonStr)){
//					System.out.println("过于频繁调用企查查，超出企查查询次数，暂时休眠，需人工干预，休眠10000毫秒......");
//					Thread.sleep(10000);
					Constants.QCC_PAQU_STATE = "1";
					jsonStr = getHttpReponseBody(scriptRequestUrl);
				}else{
					if(StringUtils.isNullOrEmpty(jsonStr)){
						Constants.QCC_PAQU_STATE = "2";
						jsonStr = getHttpReponseBody(scriptRequestUrl);
					}else{
						Document doc = Jsoup.parse(jsonStr);
						Elements normalLoginElements = doc.select("#normalLoginPanel");
						if((normalLoginElements!=null && normalLoginElements.size()>0)){
							Constants.QCC_PAQU_STATE = "2";
							jsonStr = getHttpReponseBody(requestUrl);
						}
					}
				}
			}
		} catch (SocketTimeoutException e) {
			System.err.println("io.github.biezhi.elves.spider.getHttpReponseBody，SocketTimeoutException，返回响应url内容，链接串为:" + requestUrl + "{{}}==>" + StringUtils.getErrorInfoFromException(e));
			
			if(Constants.IS_PROXY){
				System.out.println("io.github.biezhi.elves.spider.getHttpReponseBody，网络超时，休眠5000毫秒后，重新再调用......");
				try {
					Thread.sleep(5000);
					System.out.println("io.github.biezhi.elves.spider.getHttpReponseBody，已休眠5000毫秒，开始重新再调用getHttpReponseBody方法===>");
					Constants.QCC_PAQU_STATE = "2";
					getHttpReponseBody(requestUrl);
				} catch (InterruptedException e1) {
					e1.printStackTrace();
				}
			}
		} catch (Exception e) {
			System.err.println("io.github.biezhi.elves.spider.getHttpReponseBody，返回响应url内容，链接串为:" + requestUrl + "{{}}==>" + StringUtils.getErrorInfoFromException(e));
			
			System.out.println("io.github.biezhi.elves.spider.getHttpReponseBody，休眠5000毫秒后，重新再调用......");
			try {
				Thread.sleep(5000);
				System.out.println("io.github.biezhi.elves.spider.getHttpReponseBody，已休眠5000毫秒，开始重新再调用getHttpReponseBody方法===>");
				getHttpReponseBody(requestUrl);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
		return jsonStr;
	}
	
	/**
	 * 获取企查查某企业法律诉讼量
	 * @param unique
	 * @return
	 */
	private int getEntnameForSusongCount(String unique){
		int companyNavCount = 0;
		try{
			String contentUrl = indexUrl + "/firm_" + unique + ".html";
			//返回响应url内容
			String responseBody = getHttpReponseBody(contentUrl);
			Document susongDoc = Jsoup.parse(responseBody);
			Elements elementsCompanyNav = susongDoc.select("#company-nav > .nav-tabs");
			if(elementsCompanyNav!=null && elementsCompanyNav.size()>0){
				String companyNavCountStr = elementsCompanyNav.select("li").get(1).select("a > span").text();
				if(!StringUtils.isNullOrEmpty(companyNavCountStr)){
					companyNavCount = Integer.parseInt(companyNavCountStr);
				}
			}
		}catch(Exception e){
			System.out.println("获取企查查某企业法律诉讼量异常{{}}==>" + StringUtils.getErrorInfoFromException(e));
		}
		return companyNavCount;
	}
	
	static final String[] tableNames = new String[]{"app_legal_info","app_shareholder","app_pri_personnel",
			"app_stock_structure_info","app_enterprise_profile_info","app_family_investment_info",
			"app_relation_profile_info","app_stock_tructure_profile_info","app_executor_info","app_referee_doc",
			"app_notice_court","app_bulletin_court"};
	/**
	 * 创建企业数据备份表(表名+统计数)
	 */
	private void createTableName() throws Exception{
		String table = "";
		boolean isSuccess = true;
		//统计去重企业名称法人代表信息表数据量
		int countAppLegalInfo = shareholderService.countAppLegalInfoForDistinctEntname();
		for(String tableName : tableNames){
			try{
				table = tableName + countAppLegalInfo;
				System.out.println(this.getClass() + ".createTableName，正在创建备份表名{{}}==>" + table);
				//创建企业数据备份表(表名+统计数)
				shareholderService.createTableName(tableName, countAppLegalInfo);
				System.out.println(this.getClass() + ".createTableName，已创建备份表名{{}}==>" + table);
			}catch(Exception e){
				isSuccess = false;
				throw new Exception(this.getClass() + ".createTableName，创建企业数据备份表(表名+统计数)异常{{}}==>" + StringUtils.getErrorInfoFromException(e));
			}
		}
		
		if(!isSuccess){
			System.out.println(this.getClass() + ".createTableName，创建备份表:" + table +"，系统异常自动停止!!!");
			System.exit(0);
		}else{
			table = "li_crawl_table_data" + countAppLegalInfo;
			try{
				System.out.println(this.getClass() + ".createTableName，正在创建备份表名{{}}==>" + table);
				//创建爬取企业列表数据备份表(表名+统计数)
				shareholderService.createTableName("li_crawl_table_data", countAppLegalInfo);
				System.out.println(this.getClass() + ".createTableName，已创建备份表名{{}}==>" + table);
			}catch(Exception e){
				isSuccess = false;
				throw new Exception(this.getClass() + ".createTableName，创建爬取企业列表数据备份表(表名+统计数)异常{{}}==>" + StringUtils.getErrorInfoFromException(e));
			}
			if(!isSuccess){
				System.out.println(this.getClass() + ".createTableName，创建备份表:" + table +"，系统异常自动停止!!!");
				System.exit(0);
			}
		}
	}
	
	/**
	 * 开始创建企业数据备份表(表名+统计数)
	 * @throws Exception 
	 * 
	 */
	private void startCreateTableName() throws Exception{
//		System.out.println("爬取量初始化值，handleRun{{}}==>" + Constants.HANDLE_RUN);
//		System.out.println("最大爬取数据量，maxRunSize{{}}==>" + maxRunSize);
//		if(Constants.HANDLE_RUN==maxRunSize){
			System.out.println(this.getClass() + ".ShareholderSpider，开始执行创建企业数据备份表(表名+统计数)操作......");
			//创建企业数据备份表(表名+统计数)
			createTableName();
			System.out.println(this.getClass() + ".ShareholderSpider，已执行完创建企业数据备份表(表名+统计数)操作......");
			
			Constants.HANDLE_RUN = pageSize;
			System.out.println(this.getClass() + ".ShareholderSpider，重置爬取量初始化值{{}}==>" + Constants.HANDLE_RUN);
//		}
	}
	
	public static void main(String[] args) throws Exception {
		ShareholderSpider shareholderSpider = new ShareholderSpider("广东工商企业");
		shareholderSpider.startShareholder();
	}
}